text
stringlengths
938
1.05M
////////////////////////////////////////////////////////////////////////////////// // d_partial_FFM_gate_6b.v for Cosmos OpenSSD // Copyright (c) 2015 Hanyang University ENC Lab. // Contributed by Jinwoo Jeong <[email protected]> // Ilyong Jung <[email protected]> // Yong Ho Song <[email protected]> // // This file is part of Cosmos OpenSSD. // // Cosmos OpenSSD 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. // // Cosmos OpenSSD 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 Cosmos OpenSSD; see the file COPYING. // If not, see <http://www.gnu.org/licenses/>. ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// // Company: ENC Lab. <http://enc.hanyang.ac.kr> // Engineer: Jinwoo Jeong <[email protected]> // Ilyong Jung <[email protected]> // // Project Name: Cosmos OpenSSD // Design Name: BCH Page Decoder // Module Name: d_partial_FFM_gate_6b // File Name: d_partial_FFM_gate_6b.v // // Version: v1.0.1-6b // // Description: // - parallel Finite Field Multiplier (FFM) module // - 2 polynomial form input, 1 polynomial form output ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// // Revision History: // // * v1.0.1 // - minor modification for releasing // // * v1.0.0 // - first draft ////////////////////////////////////////////////////////////////////////////////// `timescale 1ns / 1ps module d_partial_FFM_gate_6b ( input wire [5:0] i_a, // input term A input wire [5:0] i_b, // input term B output wire [10:0] o_r // output term result ); /////////////////////////////////////////////////////////// // CAUTION! CAUTION! CAUTION! CAUTION! CAUTION! CAUTION! // // // // ONLY FOR 6 BIT POLYNOMIAL MULTIPLICATION // // // // CAUTION! CAUTION! CAUTION! CAUTION! CAUTION! CAUTION! // /////////////////////////////////////////////////////////// // multiplication assign o_r[10] = (i_a[5]&i_b[5]); assign o_r[ 9] = (i_a[4]&i_b[5]) ^ (i_a[5]&i_b[4]); assign o_r[ 8] = (i_a[3]&i_b[5]) ^ (i_a[4]&i_b[4]) ^ (i_a[5]&i_b[3]); assign o_r[ 7] = (i_a[2]&i_b[5]) ^ (i_a[3]&i_b[4]) ^ (i_a[4]&i_b[3]) ^ (i_a[5]&i_b[2]); assign o_r[ 6] = (i_a[1]&i_b[5]) ^ (i_a[2]&i_b[4]) ^ (i_a[3]&i_b[3]) ^ (i_a[4]&i_b[2]) ^ (i_a[5]&i_b[1]); assign o_r[ 5] = (i_a[0]&i_b[5]) ^ (i_a[1]&i_b[4]) ^ (i_a[2]&i_b[3]) ^ (i_a[3]&i_b[2]) ^ (i_a[4]&i_b[1]) ^ (i_a[5]&i_b[0]); assign o_r[ 4] = (i_a[0]&i_b[4]) ^ (i_a[1]&i_b[3]) ^ (i_a[2]&i_b[2]) ^ (i_a[3]&i_b[1]) ^ (i_a[4]&i_b[0]); assign o_r[ 3] = (i_a[0]&i_b[3]) ^ (i_a[1]&i_b[2]) ^ (i_a[2]&i_b[1]) ^ (i_a[3]&i_b[0]); assign o_r[ 2] = (i_a[0]&i_b[2]) ^ (i_a[1]&i_b[1]) ^ (i_a[2]&i_b[0]); assign o_r[ 1] = (i_a[0]&i_b[1]) ^ (i_a[1]&i_b[0]); assign o_r[ 0] = (i_a[0]&i_b[0]); endmodule
////////////////////////////////////////////////////////////////////////////////// // d_partial_FFM_gate_6b.v for Cosmos OpenSSD // Copyright (c) 2015 Hanyang University ENC Lab. // Contributed by Jinwoo Jeong <[email protected]> // Ilyong Jung <[email protected]> // Yong Ho Song <[email protected]> // // This file is part of Cosmos OpenSSD. // // Cosmos OpenSSD 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. // // Cosmos OpenSSD 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 Cosmos OpenSSD; see the file COPYING. // If not, see <http://www.gnu.org/licenses/>. ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// // Company: ENC Lab. <http://enc.hanyang.ac.kr> // Engineer: Jinwoo Jeong <[email protected]> // Ilyong Jung <[email protected]> // // Project Name: Cosmos OpenSSD // Design Name: BCH Page Decoder // Module Name: d_partial_FFM_gate_6b // File Name: d_partial_FFM_gate_6b.v // // Version: v1.0.1-6b // // Description: // - parallel Finite Field Multiplier (FFM) module // - 2 polynomial form input, 1 polynomial form output ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// // Revision History: // // * v1.0.1 // - minor modification for releasing // // * v1.0.0 // - first draft ////////////////////////////////////////////////////////////////////////////////// `timescale 1ns / 1ps module d_partial_FFM_gate_6b ( input wire [5:0] i_a, // input term A input wire [5:0] i_b, // input term B output wire [10:0] o_r // output term result ); /////////////////////////////////////////////////////////// // CAUTION! CAUTION! CAUTION! CAUTION! CAUTION! CAUTION! // // // // ONLY FOR 6 BIT POLYNOMIAL MULTIPLICATION // // // // CAUTION! CAUTION! CAUTION! CAUTION! CAUTION! CAUTION! // /////////////////////////////////////////////////////////// // multiplication assign o_r[10] = (i_a[5]&i_b[5]); assign o_r[ 9] = (i_a[4]&i_b[5]) ^ (i_a[5]&i_b[4]); assign o_r[ 8] = (i_a[3]&i_b[5]) ^ (i_a[4]&i_b[4]) ^ (i_a[5]&i_b[3]); assign o_r[ 7] = (i_a[2]&i_b[5]) ^ (i_a[3]&i_b[4]) ^ (i_a[4]&i_b[3]) ^ (i_a[5]&i_b[2]); assign o_r[ 6] = (i_a[1]&i_b[5]) ^ (i_a[2]&i_b[4]) ^ (i_a[3]&i_b[3]) ^ (i_a[4]&i_b[2]) ^ (i_a[5]&i_b[1]); assign o_r[ 5] = (i_a[0]&i_b[5]) ^ (i_a[1]&i_b[4]) ^ (i_a[2]&i_b[3]) ^ (i_a[3]&i_b[2]) ^ (i_a[4]&i_b[1]) ^ (i_a[5]&i_b[0]); assign o_r[ 4] = (i_a[0]&i_b[4]) ^ (i_a[1]&i_b[3]) ^ (i_a[2]&i_b[2]) ^ (i_a[3]&i_b[1]) ^ (i_a[4]&i_b[0]); assign o_r[ 3] = (i_a[0]&i_b[3]) ^ (i_a[1]&i_b[2]) ^ (i_a[2]&i_b[1]) ^ (i_a[3]&i_b[0]); assign o_r[ 2] = (i_a[0]&i_b[2]) ^ (i_a[1]&i_b[1]) ^ (i_a[2]&i_b[0]); assign o_r[ 1] = (i_a[0]&i_b[1]) ^ (i_a[1]&i_b[0]); assign o_r[ 0] = (i_a[0]&i_b[0]); endmodule
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * 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. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // 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 REGENTS OF THE // UNIVERSITY OF CALIFORNIA 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. // ---------------------------------------------------------------------- `include "riffa.vh" module channel #( parameter C_DATA_WIDTH = 128, parameter C_MAX_READ_REQ = 2, // Max read: 000=128B, 001=256B, 010=512B, 011=1024B, 100=2048B, 101=4096B parameter C_DATA_WORD_WIDTH = clog2((C_DATA_WIDTH/32)+1) ) ( input CLK, input RST, input [2:0] CONFIG_MAX_READ_REQUEST_SIZE, // Maximum read payload: 000=128B, 001=256B, 010=512B, 011=1024B, 100=2048B, 101=4096B input [2:0] CONFIG_MAX_PAYLOAD_SIZE, // Maximum write payload: 000=128B, 001=256B, 010=512B, 011=1024B input [31:0] PIO_DATA, // Single word programmed I/O data input [C_DATA_WIDTH-1:0] ENG_DATA, // Main incoming data output SG_RX_BUF_RECVD, // Scatter gather RX buffer completely read (ready for next if applicable) input SG_RX_BUF_LEN_VALID, // Scatter gather RX buffer length valid input SG_RX_BUF_ADDR_HI_VALID, // Scatter gather RX buffer high address valid input SG_RX_BUF_ADDR_LO_VALID, // Scatter gather RX buffer low address valid output SG_TX_BUF_RECVD, // Scatter gather TX buffer completely read (ready for next if applicable) input SG_TX_BUF_LEN_VALID, // Scatter gather TX buffer length valid input SG_TX_BUF_ADDR_HI_VALID, // Scatter gather TX buffer high address valid input SG_TX_BUF_ADDR_LO_VALID, // Scatter gather TX buffer low address valid input TXN_RX_LEN_VALID, // Read transaction length valid input TXN_RX_OFF_LAST_VALID, // Read transaction offset/last valid output [31:0] TXN_RX_DONE_LEN, // Read transaction actual transfer length output TXN_RX_DONE, // Read transaction done input TXN_RX_DONE_ACK, // Read transaction actual transfer length read output TXN_TX, // Write transaction notification input TXN_TX_ACK, // Write transaction acknowledged output [31:0] TXN_TX_LEN, // Write transaction length output [31:0] TXN_TX_OFF_LAST, // Write transaction offset/last output [31:0] TXN_TX_DONE_LEN, // Write transaction actual transfer length output TXN_TX_DONE, // Write transaction done input TXN_TX_DONE_ACK, // Write transaction actual transfer length read output RX_REQ, // Read request input RX_REQ_ACK, // Read request accepted output [1:0] RX_REQ_TAG, // Read request data tag output [63:0] RX_REQ_ADDR, // Read request address output [9:0] RX_REQ_LEN, // Read request length output TX_REQ, // Outgoing write request input TX_REQ_ACK, // Outgoing write request acknowledged output [63:0] TX_ADDR, // Outgoing write high address output [9:0] TX_LEN, // Outgoing write length (in 32 bit words) output [C_DATA_WIDTH-1:0] TX_DATA, // Outgoing write data input TX_DATA_REN, // Outgoing write data read enable input TX_SENT, // Outgoing write complete input [C_DATA_WORD_WIDTH-1:0] MAIN_DATA_EN, // Main incoming data enable input MAIN_DONE, // Main incoming data complete input MAIN_ERR, // Main incoming data completed with error input [C_DATA_WORD_WIDTH-1:0] SG_RX_DATA_EN, // Scatter gather for RX incoming data enable input SG_RX_DONE, // Scatter gather for RX incoming data complete input SG_RX_ERR, // Scatter gather for RX incoming data completed with error input [C_DATA_WORD_WIDTH-1:0] SG_TX_DATA_EN, // Scatter gather for TX incoming data enable input SG_TX_DONE, // Scatter gather for TX incoming data complete input SG_TX_ERR, // Scatter gather for TX incoming data completed with error input CHNL_RX_CLK, // Channel read clock output CHNL_RX, // Channel read receive signal input CHNL_RX_ACK, // Channle read received signal output CHNL_RX_LAST, // Channel last read output [31:0] CHNL_RX_LEN, // Channel read length output [30:0] CHNL_RX_OFF, // Channel read offset output [C_DATA_WIDTH-1:0] CHNL_RX_DATA, // Channel read data output CHNL_RX_DATA_VALID, // Channel read data valid input CHNL_RX_DATA_REN, // Channel read data has been recieved input CHNL_TX_CLK, // Channel write clock input CHNL_TX, // Channel write receive signal output CHNL_TX_ACK, // Channel write acknowledgement signal input CHNL_TX_LAST, // Channel last write input [31:0] CHNL_TX_LEN, // Channel write length (in 32 bit words) input [30:0] CHNL_TX_OFF, // Channel write offset input [C_DATA_WIDTH-1:0] CHNL_TX_DATA, // Channel write data input CHNL_TX_DATA_VALID, // Channel write data valid output CHNL_TX_DATA_REN // Channel write data has been recieved ); generate if(C_DATA_WIDTH == 32) begin channel_32 #( .C_DATA_WIDTH(C_DATA_WIDTH), .C_MAX_READ_REQ(C_MAX_READ_REQ) ) channel (/*AUTOINST*/ // Outputs .SG_RX_BUF_RECVD (SG_RX_BUF_RECVD), .SG_TX_BUF_RECVD (SG_TX_BUF_RECVD), .TXN_RX_DONE_LEN (TXN_RX_DONE_LEN[31:0]), .TXN_RX_DONE (TXN_RX_DONE), .TXN_TX (TXN_TX), .TXN_TX_LEN (TXN_TX_LEN[31:0]), .TXN_TX_OFF_LAST (TXN_TX_OFF_LAST[31:0]), .TXN_TX_DONE_LEN (TXN_TX_DONE_LEN[31:0]), .TXN_TX_DONE (TXN_TX_DONE), .RX_REQ (RX_REQ), .RX_REQ_TAG (RX_REQ_TAG[1:0]), .RX_REQ_ADDR (RX_REQ_ADDR[63:0]), .RX_REQ_LEN (RX_REQ_LEN[9:0]), .TX_REQ (TX_REQ), .TX_ADDR (TX_ADDR[63:0]), .TX_LEN (TX_LEN[9:0]), .TX_DATA (TX_DATA[C_DATA_WIDTH-1:0]), .CHNL_RX (CHNL_RX), .CHNL_RX_LAST (CHNL_RX_LAST), .CHNL_RX_LEN (CHNL_RX_LEN[31:0]), .CHNL_RX_OFF (CHNL_RX_OFF[30:0]), .CHNL_RX_DATA (CHNL_RX_DATA[C_DATA_WIDTH-1:0]), .CHNL_RX_DATA_VALID (CHNL_RX_DATA_VALID), .CHNL_TX_ACK (CHNL_TX_ACK), .CHNL_TX_DATA_REN (CHNL_TX_DATA_REN), // Inputs .CLK (CLK), .RST (RST), .CONFIG_MAX_READ_REQUEST_SIZE(CONFIG_MAX_READ_REQUEST_SIZE[2:0]), .CONFIG_MAX_PAYLOAD_SIZE (CONFIG_MAX_PAYLOAD_SIZE[2:0]), .PIO_DATA (PIO_DATA[31:0]), .ENG_DATA (ENG_DATA[C_DATA_WIDTH-1:0]), .SG_RX_BUF_LEN_VALID (SG_RX_BUF_LEN_VALID), .SG_RX_BUF_ADDR_HI_VALID (SG_RX_BUF_ADDR_HI_VALID), .SG_RX_BUF_ADDR_LO_VALID (SG_RX_BUF_ADDR_LO_VALID), .SG_TX_BUF_LEN_VALID (SG_TX_BUF_LEN_VALID), .SG_TX_BUF_ADDR_HI_VALID (SG_TX_BUF_ADDR_HI_VALID), .SG_TX_BUF_ADDR_LO_VALID (SG_TX_BUF_ADDR_LO_VALID), .TXN_RX_LEN_VALID (TXN_RX_LEN_VALID), .TXN_RX_OFF_LAST_VALID (TXN_RX_OFF_LAST_VALID), .TXN_RX_DONE_ACK (TXN_RX_DONE_ACK), .TXN_TX_ACK (TXN_TX_ACK), .TXN_TX_DONE_ACK (TXN_TX_DONE_ACK), .RX_REQ_ACK (RX_REQ_ACK), .TX_REQ_ACK (TX_REQ_ACK), .TX_DATA_REN (TX_DATA_REN), .TX_SENT (TX_SENT), .MAIN_DATA_EN (MAIN_DATA_EN[C_DATA_WORD_WIDTH-1:0]), .MAIN_DONE (MAIN_DONE), .MAIN_ERR (MAIN_ERR), .SG_RX_DATA_EN (SG_RX_DATA_EN[C_DATA_WORD_WIDTH-1:0]), .SG_RX_DONE (SG_RX_DONE), .SG_RX_ERR (SG_RX_ERR), .SG_TX_DATA_EN (SG_TX_DATA_EN[C_DATA_WORD_WIDTH-1:0]), .SG_TX_DONE (SG_TX_DONE), .SG_TX_ERR (SG_TX_ERR), .CHNL_RX_CLK (CHNL_RX_CLK), .CHNL_RX_ACK (CHNL_RX_ACK), .CHNL_RX_DATA_REN (CHNL_RX_DATA_REN), .CHNL_TX_CLK (CHNL_TX_CLK), .CHNL_TX (CHNL_TX), .CHNL_TX_LAST (CHNL_TX_LAST), .CHNL_TX_LEN (CHNL_TX_LEN[31:0]), .CHNL_TX_OFF (CHNL_TX_OFF[30:0]), .CHNL_TX_DATA (CHNL_TX_DATA[C_DATA_WIDTH-1:0]), .CHNL_TX_DATA_VALID (CHNL_TX_DATA_VALID)); end else if(C_DATA_WIDTH == 64) begin channel_64 #( .C_DATA_WIDTH(C_DATA_WIDTH), .C_MAX_READ_REQ(C_MAX_READ_REQ) ) channel (/*AUTOINST*/ // Outputs .SG_RX_BUF_RECVD (SG_RX_BUF_RECVD), .SG_TX_BUF_RECVD (SG_TX_BUF_RECVD), .TXN_RX_DONE_LEN (TXN_RX_DONE_LEN[31:0]), .TXN_RX_DONE (TXN_RX_DONE), .TXN_TX (TXN_TX), .TXN_TX_LEN (TXN_TX_LEN[31:0]), .TXN_TX_OFF_LAST (TXN_TX_OFF_LAST[31:0]), .TXN_TX_DONE_LEN (TXN_TX_DONE_LEN[31:0]), .TXN_TX_DONE (TXN_TX_DONE), .RX_REQ (RX_REQ), .RX_REQ_TAG (RX_REQ_TAG[1:0]), .RX_REQ_ADDR (RX_REQ_ADDR[63:0]), .RX_REQ_LEN (RX_REQ_LEN[9:0]), .TX_REQ (TX_REQ), .TX_ADDR (TX_ADDR[63:0]), .TX_LEN (TX_LEN[9:0]), .TX_DATA (TX_DATA[C_DATA_WIDTH-1:0]), .CHNL_RX (CHNL_RX), .CHNL_RX_LAST (CHNL_RX_LAST), .CHNL_RX_LEN (CHNL_RX_LEN[31:0]), .CHNL_RX_OFF (CHNL_RX_OFF[30:0]), .CHNL_RX_DATA (CHNL_RX_DATA[C_DATA_WIDTH-1:0]), .CHNL_RX_DATA_VALID (CHNL_RX_DATA_VALID), .CHNL_TX_ACK (CHNL_TX_ACK), .CHNL_TX_DATA_REN (CHNL_TX_DATA_REN), // Inputs .CLK (CLK), .RST (RST), .CONFIG_MAX_READ_REQUEST_SIZE(CONFIG_MAX_READ_REQUEST_SIZE[2:0]), .CONFIG_MAX_PAYLOAD_SIZE (CONFIG_MAX_PAYLOAD_SIZE[2:0]), .PIO_DATA (PIO_DATA[31:0]), .ENG_DATA (ENG_DATA[C_DATA_WIDTH-1:0]), .SG_RX_BUF_LEN_VALID (SG_RX_BUF_LEN_VALID), .SG_RX_BUF_ADDR_HI_VALID (SG_RX_BUF_ADDR_HI_VALID), .SG_RX_BUF_ADDR_LO_VALID (SG_RX_BUF_ADDR_LO_VALID), .SG_TX_BUF_LEN_VALID (SG_TX_BUF_LEN_VALID), .SG_TX_BUF_ADDR_HI_VALID (SG_TX_BUF_ADDR_HI_VALID), .SG_TX_BUF_ADDR_LO_VALID (SG_TX_BUF_ADDR_LO_VALID), .TXN_RX_LEN_VALID (TXN_RX_LEN_VALID), .TXN_RX_OFF_LAST_VALID (TXN_RX_OFF_LAST_VALID), .TXN_RX_DONE_ACK (TXN_RX_DONE_ACK), .TXN_TX_ACK (TXN_TX_ACK), .TXN_TX_DONE_ACK (TXN_TX_DONE_ACK), .RX_REQ_ACK (RX_REQ_ACK), .TX_REQ_ACK (TX_REQ_ACK), .TX_DATA_REN (TX_DATA_REN), .TX_SENT (TX_SENT), .MAIN_DATA_EN (MAIN_DATA_EN[C_DATA_WORD_WIDTH-1:0]), .MAIN_DONE (MAIN_DONE), .MAIN_ERR (MAIN_ERR), .SG_RX_DATA_EN (SG_RX_DATA_EN[C_DATA_WORD_WIDTH-1:0]), .SG_RX_DONE (SG_RX_DONE), .SG_RX_ERR (SG_RX_ERR), .SG_TX_DATA_EN (SG_TX_DATA_EN[C_DATA_WORD_WIDTH-1:0]), .SG_TX_DONE (SG_TX_DONE), .SG_TX_ERR (SG_TX_ERR), .CHNL_RX_CLK (CHNL_RX_CLK), .CHNL_RX_ACK (CHNL_RX_ACK), .CHNL_RX_DATA_REN (CHNL_RX_DATA_REN), .CHNL_TX_CLK (CHNL_TX_CLK), .CHNL_TX (CHNL_TX), .CHNL_TX_LAST (CHNL_TX_LAST), .CHNL_TX_LEN (CHNL_TX_LEN[31:0]), .CHNL_TX_OFF (CHNL_TX_OFF[30:0]), .CHNL_TX_DATA (CHNL_TX_DATA[C_DATA_WIDTH-1:0]), .CHNL_TX_DATA_VALID (CHNL_TX_DATA_VALID)); end else if(C_DATA_WIDTH == 128) begin channel_128 #( .C_DATA_WIDTH(C_DATA_WIDTH), .C_MAX_READ_REQ(C_MAX_READ_REQ) ) channel (/*AUTOINST*/ // Outputs .SG_RX_BUF_RECVD (SG_RX_BUF_RECVD), .SG_TX_BUF_RECVD (SG_TX_BUF_RECVD), .TXN_RX_DONE_LEN (TXN_RX_DONE_LEN[31:0]), .TXN_RX_DONE (TXN_RX_DONE), .TXN_TX (TXN_TX), .TXN_TX_LEN (TXN_TX_LEN[31:0]), .TXN_TX_OFF_LAST (TXN_TX_OFF_LAST[31:0]), .TXN_TX_DONE_LEN (TXN_TX_DONE_LEN[31:0]), .TXN_TX_DONE (TXN_TX_DONE), .RX_REQ (RX_REQ), .RX_REQ_TAG (RX_REQ_TAG[1:0]), .RX_REQ_ADDR (RX_REQ_ADDR[63:0]), .RX_REQ_LEN (RX_REQ_LEN[9:0]), .TX_REQ (TX_REQ), .TX_ADDR (TX_ADDR[63:0]), .TX_LEN (TX_LEN[9:0]), .TX_DATA (TX_DATA[C_DATA_WIDTH-1:0]), .CHNL_RX (CHNL_RX), .CHNL_RX_LAST (CHNL_RX_LAST), .CHNL_RX_LEN (CHNL_RX_LEN[31:0]), .CHNL_RX_OFF (CHNL_RX_OFF[30:0]), .CHNL_RX_DATA (CHNL_RX_DATA[C_DATA_WIDTH-1:0]), .CHNL_RX_DATA_VALID (CHNL_RX_DATA_VALID), .CHNL_TX_ACK (CHNL_TX_ACK), .CHNL_TX_DATA_REN (CHNL_TX_DATA_REN), // Inputs .CLK (CLK), .RST (RST), .CONFIG_MAX_READ_REQUEST_SIZE(CONFIG_MAX_READ_REQUEST_SIZE[2:0]), .CONFIG_MAX_PAYLOAD_SIZE (CONFIG_MAX_PAYLOAD_SIZE[2:0]), .PIO_DATA (PIO_DATA[31:0]), .ENG_DATA (ENG_DATA[C_DATA_WIDTH-1:0]), .SG_RX_BUF_LEN_VALID (SG_RX_BUF_LEN_VALID), .SG_RX_BUF_ADDR_HI_VALID (SG_RX_BUF_ADDR_HI_VALID), .SG_RX_BUF_ADDR_LO_VALID (SG_RX_BUF_ADDR_LO_VALID), .SG_TX_BUF_LEN_VALID (SG_TX_BUF_LEN_VALID), .SG_TX_BUF_ADDR_HI_VALID (SG_TX_BUF_ADDR_HI_VALID), .SG_TX_BUF_ADDR_LO_VALID (SG_TX_BUF_ADDR_LO_VALID), .TXN_RX_LEN_VALID (TXN_RX_LEN_VALID), .TXN_RX_OFF_LAST_VALID (TXN_RX_OFF_LAST_VALID), .TXN_RX_DONE_ACK (TXN_RX_DONE_ACK), .TXN_TX_ACK (TXN_TX_ACK), .TXN_TX_DONE_ACK (TXN_TX_DONE_ACK), .RX_REQ_ACK (RX_REQ_ACK), .TX_REQ_ACK (TX_REQ_ACK), .TX_DATA_REN (TX_DATA_REN), .TX_SENT (TX_SENT), .MAIN_DATA_EN (MAIN_DATA_EN[C_DATA_WORD_WIDTH-1:0]), .MAIN_DONE (MAIN_DONE), .MAIN_ERR (MAIN_ERR), .SG_RX_DATA_EN (SG_RX_DATA_EN[C_DATA_WORD_WIDTH-1:0]), .SG_RX_DONE (SG_RX_DONE), .SG_RX_ERR (SG_RX_ERR), .SG_TX_DATA_EN (SG_TX_DATA_EN[C_DATA_WORD_WIDTH-1:0]), .SG_TX_DONE (SG_TX_DONE), .SG_TX_ERR (SG_TX_ERR), .CHNL_RX_CLK (CHNL_RX_CLK), .CHNL_RX_ACK (CHNL_RX_ACK), .CHNL_RX_DATA_REN (CHNL_RX_DATA_REN), .CHNL_TX_CLK (CHNL_TX_CLK), .CHNL_TX (CHNL_TX), .CHNL_TX_LAST (CHNL_TX_LAST), .CHNL_TX_LEN (CHNL_TX_LEN[31:0]), .CHNL_TX_OFF (CHNL_TX_OFF[30:0]), .CHNL_TX_DATA (CHNL_TX_DATA[C_DATA_WIDTH-1:0]), .CHNL_TX_DATA_VALID (CHNL_TX_DATA_VALID)); end endgenerate endmodule // Local Variables: // verilog-library-directories:("." "import") // End:
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * 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. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // 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 REGENTS OF THE // UNIVERSITY OF CALIFORNIA 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. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: tx_data_pipeline // Version: 1.0 // Verilog Standard: Verilog-2001 // // Description: The TX Data pipeline module takes arbitrarily 32-bit aligned data // from the WR_TX_DATA interface and shifts the data so that it is 0-bit // aligned. This data is presented on a set of N fifos, where N = // (C_DATA_WIDTH/32). Each fifo provides it's own VALID signal and is // controlled by a READY signal. Each fifo also provides an independent DATA bus // and additional END_FLAG signal which inidicates that the dword provided in this // fifo is the last dword in the current payload. The START_FLAG signal indicates // that the dword at index N = 0 is the start of a new packet. // // The TX Data Pipeline is built from two modules: tx_data_shift.v and // tx_data_fifo.v. See these modules for more information. // // Author: Dustin Richmond (@darichmond) //---------------------------------------------------------------------------- `include "trellis.vh" // Defines the user-facing signal widths. module tx_data_pipeline #(parameter C_DATA_WIDTH = 128, parameter C_PIPELINE_INPUT = 1, parameter C_PIPELINE_OUTPUT = 1, parameter C_MAX_PAYLOAD_DWORDS = 256, parameter C_DEPTH_PACKETS = 10, parameter C_VENDOR = "ALTERA") (// Interface: Clocks input CLK, // Interface: Resets input RST_IN, // Interface: WR TX DATA input WR_TX_DATA_VALID, input [C_DATA_WIDTH-1:0] WR_TX_DATA, input WR_TX_DATA_START_FLAG, input [clog2s(C_DATA_WIDTH/32)-1:0] WR_TX_DATA_START_OFFSET, input WR_TX_DATA_END_FLAG, input [clog2s(C_DATA_WIDTH/32)-1:0] WR_TX_DATA_END_OFFSET, output WR_TX_DATA_READY, // Interface: TX DATA FIFOS input [(C_DATA_WIDTH/32)-1:0] RD_TX_DATA_WORD_READY, output [C_DATA_WIDTH-1:0] RD_TX_DATA, output [(C_DATA_WIDTH/32)-1:0] RD_TX_DATA_END_FLAGS, output RD_TX_DATA_START_FLAG, output [(C_DATA_WIDTH/32)-1:0] RD_TX_DATA_WORD_VALID, output RD_TX_DATA_PACKET_VALID); wire wRdTxDataValid; wire wRdTxDataReady; wire wRdTxDataStartFlag; wire [C_DATA_WIDTH-1:0] wRdTxData; wire [(C_DATA_WIDTH/32)-1:0] wRdTxDataEndFlags; wire [(C_DATA_WIDTH/32)-1:0] wRdTxDataWordValid; /*AUTOWIRE*/ /*AUTOINPUT*/ /*AUTOOUTPUT*/ tx_data_shift #(.C_PIPELINE_OUTPUT (0), /*AUTOINSTPARAM*/ // Parameters .C_PIPELINE_INPUT (C_PIPELINE_INPUT), .C_DATA_WIDTH (C_DATA_WIDTH), .C_VENDOR (C_VENDOR)) tx_shift_inst (// Outputs .RD_TX_DATA (wRdTxData), .RD_TX_DATA_VALID (wRdTxDataValid), .RD_TX_DATA_START_FLAG (wRdTxDataStartFlag), .RD_TX_DATA_WORD_VALID (wRdTxDataWordValid), .RD_TX_DATA_END_FLAGS (wRdTxDataEndFlags), // Inputs .RD_TX_DATA_READY (wRdTxDataReady), /*AUTOINST*/ // Outputs .WR_TX_DATA_READY (WR_TX_DATA_READY), // Inputs .CLK (CLK), .RST_IN (RST_IN), .WR_TX_DATA_VALID (WR_TX_DATA_VALID), .WR_TX_DATA (WR_TX_DATA[C_DATA_WIDTH-1:0]), .WR_TX_DATA_START_FLAG (WR_TX_DATA_START_FLAG), .WR_TX_DATA_START_OFFSET (WR_TX_DATA_START_OFFSET[clog2s(C_DATA_WIDTH/32)-1:0]), .WR_TX_DATA_END_FLAG (WR_TX_DATA_END_FLAG), .WR_TX_DATA_END_OFFSET (WR_TX_DATA_END_OFFSET[clog2s(C_DATA_WIDTH/32)-1:0])); // TX Data Fifo tx_data_fifo #(// Parameters .C_PIPELINE_INPUT (1), /*AUTOINSTPARAM*/ // Parameters .C_DEPTH_PACKETS (C_DEPTH_PACKETS), .C_DATA_WIDTH (C_DATA_WIDTH), .C_MAX_PAYLOAD_DWORDS (C_MAX_PAYLOAD_DWORDS)) txdf_inst (// Outputs .WR_TX_DATA_READY (wRdTxDataReady), .RD_TX_DATA (RD_TX_DATA[C_DATA_WIDTH-1:0]), .RD_TX_DATA_START_FLAG (RD_TX_DATA_START_FLAG), .RD_TX_DATA_WORD_VALID (RD_TX_DATA_WORD_VALID[(C_DATA_WIDTH/32)-1:0]), .RD_TX_DATA_END_FLAGS (RD_TX_DATA_END_FLAGS[(C_DATA_WIDTH/32)-1:0]), .RD_TX_DATA_PACKET_VALID (RD_TX_DATA_PACKET_VALID), // Inputs .WR_TX_DATA (wRdTxData), .WR_TX_DATA_VALID (wRdTxDataValid), .WR_TX_DATA_START_FLAG (wRdTxDataStartFlag), .WR_TX_DATA_WORD_VALID (wRdTxDataWordValid), .WR_TX_DATA_END_FLAGS (wRdTxDataEndFlags), .RD_TX_DATA_WORD_READY (RD_TX_DATA_WORD_READY), /*AUTOINST*/ // Inputs .CLK (CLK), .RST_IN (RST_IN)); endmodule // Local Variables: // verilog-library-directories:("." "../../../common/") // End:
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * 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. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // 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 REGENTS OF THE // UNIVERSITY OF CALIFORNIA 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. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: tx_data_pipeline // Version: 1.0 // Verilog Standard: Verilog-2001 // // Description: The TX Data pipeline module takes arbitrarily 32-bit aligned data // from the WR_TX_DATA interface and shifts the data so that it is 0-bit // aligned. This data is presented on a set of N fifos, where N = // (C_DATA_WIDTH/32). Each fifo provides it's own VALID signal and is // controlled by a READY signal. Each fifo also provides an independent DATA bus // and additional END_FLAG signal which inidicates that the dword provided in this // fifo is the last dword in the current payload. The START_FLAG signal indicates // that the dword at index N = 0 is the start of a new packet. // // The TX Data Pipeline is built from two modules: tx_data_shift.v and // tx_data_fifo.v. See these modules for more information. // // Author: Dustin Richmond (@darichmond) //---------------------------------------------------------------------------- `include "trellis.vh" // Defines the user-facing signal widths. module tx_data_pipeline #(parameter C_DATA_WIDTH = 128, parameter C_PIPELINE_INPUT = 1, parameter C_PIPELINE_OUTPUT = 1, parameter C_MAX_PAYLOAD_DWORDS = 256, parameter C_DEPTH_PACKETS = 10, parameter C_VENDOR = "ALTERA") (// Interface: Clocks input CLK, // Interface: Resets input RST_IN, // Interface: WR TX DATA input WR_TX_DATA_VALID, input [C_DATA_WIDTH-1:0] WR_TX_DATA, input WR_TX_DATA_START_FLAG, input [clog2s(C_DATA_WIDTH/32)-1:0] WR_TX_DATA_START_OFFSET, input WR_TX_DATA_END_FLAG, input [clog2s(C_DATA_WIDTH/32)-1:0] WR_TX_DATA_END_OFFSET, output WR_TX_DATA_READY, // Interface: TX DATA FIFOS input [(C_DATA_WIDTH/32)-1:0] RD_TX_DATA_WORD_READY, output [C_DATA_WIDTH-1:0] RD_TX_DATA, output [(C_DATA_WIDTH/32)-1:0] RD_TX_DATA_END_FLAGS, output RD_TX_DATA_START_FLAG, output [(C_DATA_WIDTH/32)-1:0] RD_TX_DATA_WORD_VALID, output RD_TX_DATA_PACKET_VALID); wire wRdTxDataValid; wire wRdTxDataReady; wire wRdTxDataStartFlag; wire [C_DATA_WIDTH-1:0] wRdTxData; wire [(C_DATA_WIDTH/32)-1:0] wRdTxDataEndFlags; wire [(C_DATA_WIDTH/32)-1:0] wRdTxDataWordValid; /*AUTOWIRE*/ /*AUTOINPUT*/ /*AUTOOUTPUT*/ tx_data_shift #(.C_PIPELINE_OUTPUT (0), /*AUTOINSTPARAM*/ // Parameters .C_PIPELINE_INPUT (C_PIPELINE_INPUT), .C_DATA_WIDTH (C_DATA_WIDTH), .C_VENDOR (C_VENDOR)) tx_shift_inst (// Outputs .RD_TX_DATA (wRdTxData), .RD_TX_DATA_VALID (wRdTxDataValid), .RD_TX_DATA_START_FLAG (wRdTxDataStartFlag), .RD_TX_DATA_WORD_VALID (wRdTxDataWordValid), .RD_TX_DATA_END_FLAGS (wRdTxDataEndFlags), // Inputs .RD_TX_DATA_READY (wRdTxDataReady), /*AUTOINST*/ // Outputs .WR_TX_DATA_READY (WR_TX_DATA_READY), // Inputs .CLK (CLK), .RST_IN (RST_IN), .WR_TX_DATA_VALID (WR_TX_DATA_VALID), .WR_TX_DATA (WR_TX_DATA[C_DATA_WIDTH-1:0]), .WR_TX_DATA_START_FLAG (WR_TX_DATA_START_FLAG), .WR_TX_DATA_START_OFFSET (WR_TX_DATA_START_OFFSET[clog2s(C_DATA_WIDTH/32)-1:0]), .WR_TX_DATA_END_FLAG (WR_TX_DATA_END_FLAG), .WR_TX_DATA_END_OFFSET (WR_TX_DATA_END_OFFSET[clog2s(C_DATA_WIDTH/32)-1:0])); // TX Data Fifo tx_data_fifo #(// Parameters .C_PIPELINE_INPUT (1), /*AUTOINSTPARAM*/ // Parameters .C_DEPTH_PACKETS (C_DEPTH_PACKETS), .C_DATA_WIDTH (C_DATA_WIDTH), .C_MAX_PAYLOAD_DWORDS (C_MAX_PAYLOAD_DWORDS)) txdf_inst (// Outputs .WR_TX_DATA_READY (wRdTxDataReady), .RD_TX_DATA (RD_TX_DATA[C_DATA_WIDTH-1:0]), .RD_TX_DATA_START_FLAG (RD_TX_DATA_START_FLAG), .RD_TX_DATA_WORD_VALID (RD_TX_DATA_WORD_VALID[(C_DATA_WIDTH/32)-1:0]), .RD_TX_DATA_END_FLAGS (RD_TX_DATA_END_FLAGS[(C_DATA_WIDTH/32)-1:0]), .RD_TX_DATA_PACKET_VALID (RD_TX_DATA_PACKET_VALID), // Inputs .WR_TX_DATA (wRdTxData), .WR_TX_DATA_VALID (wRdTxDataValid), .WR_TX_DATA_START_FLAG (wRdTxDataStartFlag), .WR_TX_DATA_WORD_VALID (wRdTxDataWordValid), .WR_TX_DATA_END_FLAGS (wRdTxDataEndFlags), .RD_TX_DATA_WORD_READY (RD_TX_DATA_WORD_READY), /*AUTOINST*/ // Inputs .CLK (CLK), .RST_IN (RST_IN)); endmodule // Local Variables: // verilog-library-directories:("." "../../../common/") // End:
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * 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. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // 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 REGENTS OF THE // UNIVERSITY OF CALIFORNIA 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. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: tx_data_shift.v // Version: 1.0 // Verilog Standard: Verilog-2001 // // Description: The TX Data Shift module takes arbitrarily 32-bit aligned data // from the WR_TX_DATA interface and shifts the data so that it is 0-bit aligned // on the output RD_TX_DATA interface. The VALID, END_OFFSET, and END_FLAG signal // in the WR_TX_DATA interface are replaced by WORD_VALID and END_FLAGS signals in // the RD_TX_DATA interface. Each bit in the WORD_VALID bus indicates that the // corresponding dword in the RD_TX_DATA bus is valid. Each bit in the END_FLAGS // bus indicates that the end of the payload occurs at the corresponding dword in // the RD_TX_DATA bus. // // The core of the TX_DATA_SHIFT module is a set of N multiplexers, where N = // (C_DATA_WIDTH/32). The multiplexers are surrounded by a set of optional // input and output registers with output wires wWrTxData* and input wires // wRdTxData*. Each register in the array rMuxSelect choses which mux input // desplay on the mux output. The values of the registers are set based on the // value of wWrTxDataStartOffset. These registers are enabled when // wWrTxDataStartFlag is 1 and their value set based on the value of // wWrTxDataStartOffset. // // Each bit in the VALID bus is determined by the result of two masks, // wRdTxEndFlagMask and wRdTxStartFlagMask, to make wRdTxDataValid. The start flag // mask is active when wWrTxDataStartFlag is 1, based on wWrTxDataStartOffset. The // end flag mask is active when wWrTxDataEndFlag is 1, based on // wWrTxDataEndOffset. // // TODO: // - Using WORD_VALID is a little bit confusing. I should bring back VALID as well // - WORD_VALID should be DWORD_VALID // - Use a uniform naming scheme for C_DATA_WIDTH/32 // - Is there a more efficient way to implement the wRdTxStartMaskFlag? Perhaps using the reset of a register? // Author: Dustin Richmond (@darichmond) //----------------------------------------------------------------------------- `timescale 1ns/1ns `include "trellis.vh" module tx_data_shift #( parameter C_PIPELINE_OUTPUT = 1, parameter C_PIPELINE_INPUT = 1, parameter C_DATA_WIDTH = 128, parameter C_VENDOR = "ALTERA" ) ( // Interface: Clocks input CLK, // Interface: Reset input RST_IN, // Interface: WR TX DATA input WR_TX_DATA_VALID, input [C_DATA_WIDTH-1:0] WR_TX_DATA, input WR_TX_DATA_START_FLAG, input [clog2s(C_DATA_WIDTH/32)-1:0] WR_TX_DATA_START_OFFSET, input WR_TX_DATA_END_FLAG, input [clog2s(C_DATA_WIDTH/32)-1:0] WR_TX_DATA_END_OFFSET, output WR_TX_DATA_READY, // Interface: RD TX DATA input RD_TX_DATA_READY, output [C_DATA_WIDTH-1:0] RD_TX_DATA, output RD_TX_DATA_START_FLAG, output [(C_DATA_WIDTH/32)-1:0] RD_TX_DATA_WORD_VALID, output [(C_DATA_WIDTH/32)-1:0] RD_TX_DATA_END_FLAGS, output RD_TX_DATA_VALID ); localparam C_ROTATE_BITS = clog2s(C_DATA_WIDTH/32); localparam C_NUM_MUXES = (C_DATA_WIDTH/32); localparam C_SELECT_WIDTH = C_DATA_WIDTH/32; localparam C_MASK_WIDTH = C_DATA_WIDTH/32; localparam C_AGGREGATE_WIDTH = C_DATA_WIDTH; genvar i; wire wWrTxDataValid; wire [C_DATA_WIDTH-1:0] wWrTxData; wire wWrTxDataStartFlag; wire [clog2s(C_DATA_WIDTH/32)-1:0] wWrTxDataStartOffset; wire wWrTxDataEndFlag; wire [clog2s(C_DATA_WIDTH/32)-1:0] wWrTxDataEndOffset; wire [(C_DATA_WIDTH/32)-1:0] wWrTxEndFlagMask; wire [(C_DATA_WIDTH/32)-1:0] wWrTxDataEndFlags; wire wWrTxDataReady; wire wRdTxDataReady; wire [C_DATA_WIDTH-1:0] wRdTxData; wire wRdTxDataStartFlag; wire [(C_DATA_WIDTH/32)-1:0] wRdTxDataEndFlags; wire [(C_DATA_WIDTH/32)-1:0] wRdTxDataWordValid; wire [(C_DATA_WIDTH/32)-1:0] wRdTxStartFlagMask; wire [(C_DATA_WIDTH/32)-1:0] wRdTxEndFlagMask; wire wRdTxDataValid; // wSelectDefault is the default select value for each mux, 1 << i where i // is the mux/dword index. wire [C_SELECT_WIDTH-1:0] wSelectDefault[C_NUM_MUXES-1:0]; // wSelectRotated is the value the select for each mux after the data's // start offset has been applied and until the end flag is seen. wire [C_SELECT_WIDTH-1:0] wSelectRotated[C_NUM_MUXES-1:0]; reg [C_SELECT_WIDTH-1:0] rMuxSelect[C_NUM_MUXES-1:0],_rMuxSelect[C_NUM_MUXES-1:0]; reg [clog2s(C_DATA_WIDTH/32)-1:0] rStartOffset,_rStartOffset; assign wWrTxDataReady = wRdTxDataReady; assign wRdTxStartFlagMask = wWrTxDataStartFlag ? {(C_DATA_WIDTH/32){1'b1}} >> wWrTxDataStartOffset: {(C_DATA_WIDTH/32){1'b1}}; assign wRdTxDataWordValid = wRdTxEndFlagMask & wRdTxStartFlagMask; assign wRdTxDataStartFlag = wWrTxDataStartFlag; assign wRdTxDataValid = wWrTxDataValid; generate for (i = 0; i < C_NUM_MUXES; i = i + 1) begin : gen_mux_default assign wSelectDefault[i] = (1 << i); end endgenerate always @(*) begin _rStartOffset = WR_TX_DATA_START_OFFSET; end always @(posedge CLK) begin if(WR_TX_DATA_READY & WR_TX_DATA_START_FLAG & WR_TX_DATA_VALID) begin rStartOffset <= _rStartOffset; end end generate for (i = 0; i < C_NUM_MUXES; i = i + 1) begin : gen_mux_select always @(*) begin _rMuxSelect[i] = wSelectRotated[i]; end always @(posedge CLK) begin if(WR_TX_DATA_READY & WR_TX_DATA_START_FLAG) begin rMuxSelect[i] <= _rMuxSelect[i]; end end end endgenerate pipeline #(// Parameters .C_WIDTH (C_DATA_WIDTH+2*(1+clog2s(C_DATA_WIDTH/32))), .C_USE_MEMORY (0), .C_DEPTH (C_PIPELINE_INPUT?1:0) /*AUTOINSTPARAM*/) input_register ( // Outputs .WR_DATA_READY (WR_TX_DATA_READY), .RD_DATA ({wWrTxData,wWrTxDataStartFlag,wWrTxDataStartOffset,wWrTxDataEndFlag,wWrTxDataEndOffset}), .RD_DATA_VALID (wWrTxDataValid), // Inputs .WR_DATA ({WR_TX_DATA,WR_TX_DATA_START_FLAG,WR_TX_DATA_START_OFFSET, WR_TX_DATA_END_FLAG,WR_TX_DATA_END_OFFSET}), .WR_DATA_VALID (WR_TX_DATA_VALID), .RD_DATA_READY (wWrTxDataReady), /*AUTOINST*/ // Inputs .CLK (CLK), .RST_IN (RST_IN)); // The pipeline carries the data bus and SOF/EOF. pipeline #(// Parameters .C_WIDTH (C_DATA_WIDTH + 2*C_MASK_WIDTH + 1), .C_USE_MEMORY (0), .C_DEPTH ((C_PIPELINE_OUTPUT > 1) ? 1 : 0) /*AUTOINSTPARAM*/) output_register ( // Outputs .WR_DATA_READY (wRdTxDataReady), .RD_DATA ({RD_TX_DATA,RD_TX_DATA_START_FLAG, RD_TX_DATA_END_FLAGS,RD_TX_DATA_WORD_VALID}), .RD_DATA_VALID (RD_TX_DATA_VALID), // Inputs .WR_DATA ({wRdTxData,wRdTxDataStartFlag, wRdTxDataEndFlags,wRdTxDataWordValid}), .WR_DATA_VALID (wRdTxDataValid), .RD_DATA_READY (RD_TX_DATA_READY), /*AUTOINST*/ // Inputs .CLK (CLK), .RST_IN (RST_IN)); offset_to_mask #( .C_MASK_SWAP (0), /*AUTOINSTPARAM*/ // Parameters .C_MASK_WIDTH (C_MASK_WIDTH)) eof_convert ( // Outputs .MASK (wWrTxEndFlagMask), // Inputs .OFFSET_ENABLE (wWrTxDataEndFlag), .OFFSET (wWrTxDataEndOffset) /*AUTOINST*/); rotate #( // Parameters .C_DIRECTION ("RIGHT"), .C_WIDTH (C_DATA_WIDTH/32) /*AUTOINSTPARAM*/) em_rotate_inst ( // Outputs .RD_DATA (wRdTxEndFlagMask), // Inputs .WR_DATA (wWrTxEndFlagMask), .WR_SHIFTAMT (rStartOffset[clog2s(C_DATA_WIDTH/32)-1:0]) /*AUTOINST*/); // Determine the 1-hot dword end flag offset_flag_to_one_hot #( .C_WIDTH (C_DATA_WIDTH/32) /*AUTOINSTPARAM*/) ef_onehot_inst ( // Outputs .RD_ONE_HOT (wWrTxDataEndFlags), // Inputs .WR_OFFSET (wWrTxDataEndOffset[clog2s(C_DATA_WIDTH/32)-1:0]), .WR_FLAG (wWrTxDataEndFlag) /*AUTOINST*/); rotate #( // Parameters .C_DIRECTION ("RIGHT"), .C_WIDTH (C_DATA_WIDTH/32) /*AUTOINSTPARAM*/) ef_rotate_inst ( // Outputs .RD_DATA (wRdTxDataEndFlags), // Inputs .WR_DATA (wWrTxDataEndFlags), .WR_SHIFTAMT (rStartOffset[clog2s(C_DATA_WIDTH/32)-1:0]) /*AUTOINST*/); generate for (i = 0; i < C_NUM_MUXES; i = i + 1) begin : gen_rotates rotate #( // Parameters .C_DIRECTION ("LEFT"), .C_WIDTH ((C_DATA_WIDTH/32)) /*AUTOINSTPARAM*/) select_rotate_inst_ ( // Outputs .RD_DATA (wSelectRotated[i]), // Inputs .WR_DATA (wSelectDefault[i]), .WR_SHIFTAMT (WR_TX_DATA_START_OFFSET[C_ROTATE_BITS-1:0]) /*AUTOINST*/); end endgenerate generate for (i = 0; i < C_DATA_WIDTH/32; i = i + 1) begin : gen_multiplexers one_hot_mux #( .C_DATA_WIDTH (32), /*AUTOINSTPARAM*/ // Parameters .C_SELECT_WIDTH (C_SELECT_WIDTH), .C_AGGREGATE_WIDTH (C_AGGREGATE_WIDTH)) mux_inst_ ( // Inputs .ONE_HOT_SELECT (rMuxSelect[i]), // Outputs .ONE_HOT_OUTPUT (wRdTxData[32*i +: 32]), .ONE_HOT_INPUTS (wWrTxData) /*AUTOINST*/); end endgenerate endmodule // Local Variables: // verilog-library-directories:("." "../../../common/" "../../common/") // End:
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * 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. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // 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 REGENTS OF THE // UNIVERSITY OF CALIFORNIA 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. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: tx_data_shift.v // Version: 1.0 // Verilog Standard: Verilog-2001 // // Description: The TX Data Shift module takes arbitrarily 32-bit aligned data // from the WR_TX_DATA interface and shifts the data so that it is 0-bit aligned // on the output RD_TX_DATA interface. The VALID, END_OFFSET, and END_FLAG signal // in the WR_TX_DATA interface are replaced by WORD_VALID and END_FLAGS signals in // the RD_TX_DATA interface. Each bit in the WORD_VALID bus indicates that the // corresponding dword in the RD_TX_DATA bus is valid. Each bit in the END_FLAGS // bus indicates that the end of the payload occurs at the corresponding dword in // the RD_TX_DATA bus. // // The core of the TX_DATA_SHIFT module is a set of N multiplexers, where N = // (C_DATA_WIDTH/32). The multiplexers are surrounded by a set of optional // input and output registers with output wires wWrTxData* and input wires // wRdTxData*. Each register in the array rMuxSelect choses which mux input // desplay on the mux output. The values of the registers are set based on the // value of wWrTxDataStartOffset. These registers are enabled when // wWrTxDataStartFlag is 1 and their value set based on the value of // wWrTxDataStartOffset. // // Each bit in the VALID bus is determined by the result of two masks, // wRdTxEndFlagMask and wRdTxStartFlagMask, to make wRdTxDataValid. The start flag // mask is active when wWrTxDataStartFlag is 1, based on wWrTxDataStartOffset. The // end flag mask is active when wWrTxDataEndFlag is 1, based on // wWrTxDataEndOffset. // // TODO: // - Using WORD_VALID is a little bit confusing. I should bring back VALID as well // - WORD_VALID should be DWORD_VALID // - Use a uniform naming scheme for C_DATA_WIDTH/32 // - Is there a more efficient way to implement the wRdTxStartMaskFlag? Perhaps using the reset of a register? // Author: Dustin Richmond (@darichmond) //----------------------------------------------------------------------------- `timescale 1ns/1ns `include "trellis.vh" module tx_data_shift #( parameter C_PIPELINE_OUTPUT = 1, parameter C_PIPELINE_INPUT = 1, parameter C_DATA_WIDTH = 128, parameter C_VENDOR = "ALTERA" ) ( // Interface: Clocks input CLK, // Interface: Reset input RST_IN, // Interface: WR TX DATA input WR_TX_DATA_VALID, input [C_DATA_WIDTH-1:0] WR_TX_DATA, input WR_TX_DATA_START_FLAG, input [clog2s(C_DATA_WIDTH/32)-1:0] WR_TX_DATA_START_OFFSET, input WR_TX_DATA_END_FLAG, input [clog2s(C_DATA_WIDTH/32)-1:0] WR_TX_DATA_END_OFFSET, output WR_TX_DATA_READY, // Interface: RD TX DATA input RD_TX_DATA_READY, output [C_DATA_WIDTH-1:0] RD_TX_DATA, output RD_TX_DATA_START_FLAG, output [(C_DATA_WIDTH/32)-1:0] RD_TX_DATA_WORD_VALID, output [(C_DATA_WIDTH/32)-1:0] RD_TX_DATA_END_FLAGS, output RD_TX_DATA_VALID ); localparam C_ROTATE_BITS = clog2s(C_DATA_WIDTH/32); localparam C_NUM_MUXES = (C_DATA_WIDTH/32); localparam C_SELECT_WIDTH = C_DATA_WIDTH/32; localparam C_MASK_WIDTH = C_DATA_WIDTH/32; localparam C_AGGREGATE_WIDTH = C_DATA_WIDTH; genvar i; wire wWrTxDataValid; wire [C_DATA_WIDTH-1:0] wWrTxData; wire wWrTxDataStartFlag; wire [clog2s(C_DATA_WIDTH/32)-1:0] wWrTxDataStartOffset; wire wWrTxDataEndFlag; wire [clog2s(C_DATA_WIDTH/32)-1:0] wWrTxDataEndOffset; wire [(C_DATA_WIDTH/32)-1:0] wWrTxEndFlagMask; wire [(C_DATA_WIDTH/32)-1:0] wWrTxDataEndFlags; wire wWrTxDataReady; wire wRdTxDataReady; wire [C_DATA_WIDTH-1:0] wRdTxData; wire wRdTxDataStartFlag; wire [(C_DATA_WIDTH/32)-1:0] wRdTxDataEndFlags; wire [(C_DATA_WIDTH/32)-1:0] wRdTxDataWordValid; wire [(C_DATA_WIDTH/32)-1:0] wRdTxStartFlagMask; wire [(C_DATA_WIDTH/32)-1:0] wRdTxEndFlagMask; wire wRdTxDataValid; // wSelectDefault is the default select value for each mux, 1 << i where i // is the mux/dword index. wire [C_SELECT_WIDTH-1:0] wSelectDefault[C_NUM_MUXES-1:0]; // wSelectRotated is the value the select for each mux after the data's // start offset has been applied and until the end flag is seen. wire [C_SELECT_WIDTH-1:0] wSelectRotated[C_NUM_MUXES-1:0]; reg [C_SELECT_WIDTH-1:0] rMuxSelect[C_NUM_MUXES-1:0],_rMuxSelect[C_NUM_MUXES-1:0]; reg [clog2s(C_DATA_WIDTH/32)-1:0] rStartOffset,_rStartOffset; assign wWrTxDataReady = wRdTxDataReady; assign wRdTxStartFlagMask = wWrTxDataStartFlag ? {(C_DATA_WIDTH/32){1'b1}} >> wWrTxDataStartOffset: {(C_DATA_WIDTH/32){1'b1}}; assign wRdTxDataWordValid = wRdTxEndFlagMask & wRdTxStartFlagMask; assign wRdTxDataStartFlag = wWrTxDataStartFlag; assign wRdTxDataValid = wWrTxDataValid; generate for (i = 0; i < C_NUM_MUXES; i = i + 1) begin : gen_mux_default assign wSelectDefault[i] = (1 << i); end endgenerate always @(*) begin _rStartOffset = WR_TX_DATA_START_OFFSET; end always @(posedge CLK) begin if(WR_TX_DATA_READY & WR_TX_DATA_START_FLAG & WR_TX_DATA_VALID) begin rStartOffset <= _rStartOffset; end end generate for (i = 0; i < C_NUM_MUXES; i = i + 1) begin : gen_mux_select always @(*) begin _rMuxSelect[i] = wSelectRotated[i]; end always @(posedge CLK) begin if(WR_TX_DATA_READY & WR_TX_DATA_START_FLAG) begin rMuxSelect[i] <= _rMuxSelect[i]; end end end endgenerate pipeline #(// Parameters .C_WIDTH (C_DATA_WIDTH+2*(1+clog2s(C_DATA_WIDTH/32))), .C_USE_MEMORY (0), .C_DEPTH (C_PIPELINE_INPUT?1:0) /*AUTOINSTPARAM*/) input_register ( // Outputs .WR_DATA_READY (WR_TX_DATA_READY), .RD_DATA ({wWrTxData,wWrTxDataStartFlag,wWrTxDataStartOffset,wWrTxDataEndFlag,wWrTxDataEndOffset}), .RD_DATA_VALID (wWrTxDataValid), // Inputs .WR_DATA ({WR_TX_DATA,WR_TX_DATA_START_FLAG,WR_TX_DATA_START_OFFSET, WR_TX_DATA_END_FLAG,WR_TX_DATA_END_OFFSET}), .WR_DATA_VALID (WR_TX_DATA_VALID), .RD_DATA_READY (wWrTxDataReady), /*AUTOINST*/ // Inputs .CLK (CLK), .RST_IN (RST_IN)); // The pipeline carries the data bus and SOF/EOF. pipeline #(// Parameters .C_WIDTH (C_DATA_WIDTH + 2*C_MASK_WIDTH + 1), .C_USE_MEMORY (0), .C_DEPTH ((C_PIPELINE_OUTPUT > 1) ? 1 : 0) /*AUTOINSTPARAM*/) output_register ( // Outputs .WR_DATA_READY (wRdTxDataReady), .RD_DATA ({RD_TX_DATA,RD_TX_DATA_START_FLAG, RD_TX_DATA_END_FLAGS,RD_TX_DATA_WORD_VALID}), .RD_DATA_VALID (RD_TX_DATA_VALID), // Inputs .WR_DATA ({wRdTxData,wRdTxDataStartFlag, wRdTxDataEndFlags,wRdTxDataWordValid}), .WR_DATA_VALID (wRdTxDataValid), .RD_DATA_READY (RD_TX_DATA_READY), /*AUTOINST*/ // Inputs .CLK (CLK), .RST_IN (RST_IN)); offset_to_mask #( .C_MASK_SWAP (0), /*AUTOINSTPARAM*/ // Parameters .C_MASK_WIDTH (C_MASK_WIDTH)) eof_convert ( // Outputs .MASK (wWrTxEndFlagMask), // Inputs .OFFSET_ENABLE (wWrTxDataEndFlag), .OFFSET (wWrTxDataEndOffset) /*AUTOINST*/); rotate #( // Parameters .C_DIRECTION ("RIGHT"), .C_WIDTH (C_DATA_WIDTH/32) /*AUTOINSTPARAM*/) em_rotate_inst ( // Outputs .RD_DATA (wRdTxEndFlagMask), // Inputs .WR_DATA (wWrTxEndFlagMask), .WR_SHIFTAMT (rStartOffset[clog2s(C_DATA_WIDTH/32)-1:0]) /*AUTOINST*/); // Determine the 1-hot dword end flag offset_flag_to_one_hot #( .C_WIDTH (C_DATA_WIDTH/32) /*AUTOINSTPARAM*/) ef_onehot_inst ( // Outputs .RD_ONE_HOT (wWrTxDataEndFlags), // Inputs .WR_OFFSET (wWrTxDataEndOffset[clog2s(C_DATA_WIDTH/32)-1:0]), .WR_FLAG (wWrTxDataEndFlag) /*AUTOINST*/); rotate #( // Parameters .C_DIRECTION ("RIGHT"), .C_WIDTH (C_DATA_WIDTH/32) /*AUTOINSTPARAM*/) ef_rotate_inst ( // Outputs .RD_DATA (wRdTxDataEndFlags), // Inputs .WR_DATA (wWrTxDataEndFlags), .WR_SHIFTAMT (rStartOffset[clog2s(C_DATA_WIDTH/32)-1:0]) /*AUTOINST*/); generate for (i = 0; i < C_NUM_MUXES; i = i + 1) begin : gen_rotates rotate #( // Parameters .C_DIRECTION ("LEFT"), .C_WIDTH ((C_DATA_WIDTH/32)) /*AUTOINSTPARAM*/) select_rotate_inst_ ( // Outputs .RD_DATA (wSelectRotated[i]), // Inputs .WR_DATA (wSelectDefault[i]), .WR_SHIFTAMT (WR_TX_DATA_START_OFFSET[C_ROTATE_BITS-1:0]) /*AUTOINST*/); end endgenerate generate for (i = 0; i < C_DATA_WIDTH/32; i = i + 1) begin : gen_multiplexers one_hot_mux #( .C_DATA_WIDTH (32), /*AUTOINSTPARAM*/ // Parameters .C_SELECT_WIDTH (C_SELECT_WIDTH), .C_AGGREGATE_WIDTH (C_AGGREGATE_WIDTH)) mux_inst_ ( // Inputs .ONE_HOT_SELECT (rMuxSelect[i]), // Outputs .ONE_HOT_OUTPUT (wRdTxData[32*i +: 32]), .ONE_HOT_INPUTS (wWrTxData) /*AUTOINST*/); end endgenerate endmodule // Local Variables: // verilog-library-directories:("." "../../../common/" "../../common/") // End:
/* * * Copyright (c) 2011-2013 [email protected] * * * * 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 <http://www.gnu.org/licenses/>. * */ /* * When tx_ready is high, uart_transmitter is ready to send a new byte. Drive * rx_new_byte high for one cycle, and the byte to transmit on rx_byte for one * cycle. */ module uart_receiver # ( parameter comm_clk_frequency = 100000000, parameter baud_rate = 115200 ) ( input clk, // UART interface input uart_rx, // Data received output reg tx_new_byte = 1'b0, output reg [7:0] tx_byte = 8'd0 ); localparam [15:0] baud_delay = (comm_clk_frequency / baud_rate) - 1; //----------------------------------------------------------------------------- // UART Filtering //----------------------------------------------------------------------------- wire rx; uart_filter uart_fitler_blk ( .clk (clk), .uart_rx (uart_rx), .tx_rx (rx) ); //----------------------------------------------------------------------------- // UART Decoding //----------------------------------------------------------------------------- reg old_rx = 1'b1, idle = 1'b1; reg [15:0] delay_cnt = 16'd0; reg [8:0] incoming = 9'd0; always @ (posedge clk) begin old_rx <= rx; tx_new_byte <= 1'b0; delay_cnt <= delay_cnt + 16'd1; if (delay_cnt == baud_delay) delay_cnt <= 0; if (idle && old_rx && !rx) // Start bit (falling edge) begin idle <= 1'b0; incoming <= 9'd511; delay_cnt <= 16'd0; // Synchronize timer to falling edge end else if (!idle && (delay_cnt == (baud_delay >> 1))) begin incoming <= {rx, incoming[8:1]}; // LSB first if (incoming == 9'd511 && rx) // False start bit idle <= 1'b1; if (!incoming[0]) // Expecting stop bit begin idle <= 1'b1; if (rx) begin tx_new_byte <= 1'b1; tx_byte <= incoming[8:1]; end end end end endmodule /* * Provides metastability protection, and some minimal noise filtering. * Noise is filtered with a 3-way majority vote. This removes any random single * 'clk' cycle errors. */ module uart_filter ( input clk, input uart_rx, output reg tx_rx = 1'b0 ); //----------------------------------------------------------------------------- // Metastability Protection //----------------------------------------------------------------------------- reg rx, meta; always @ (posedge clk) {rx, meta} <= {meta, uart_rx}; //----------------------------------------------------------------------------- // Noise Filtering //----------------------------------------------------------------------------- wire sample0 = rx; reg sample1, sample2; always @ (posedge clk) begin {sample2, sample1} <= {sample1, sample0}; if ((sample2 & sample1) | (sample1 & sample0) | (sample2 & sample0)) tx_rx <= 1'b1; else tx_rx <= 1'b0; end endmodule
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * 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. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // 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 REGENTS OF THE // UNIVERSITY OF CALIFORNIA 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. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: tx_port_channel_gate_128.v // Version: 1.00.a // Verilog Standard: Verilog-2001 // Description: Captures transaction open/close events as well as data // and passes it to the RD_CLK domain through the async_fifo. CHNL_TX_DATA_REN can // only be high after CHNL_TX goes high and after the CHNL_TX_ACK pulse. When // CHNL_TX drops, the channel closes (until the next transaction -- signaled by // CHNL_TX going up again). // Author: Matt Jacobsen // History: @mattj: Version 2.0 //----------------------------------------------------------------------------- `define S_TXPORTGATE128_IDLE 2'b00 `define S_TXPORTGATE128_OPENING 2'b01 `define S_TXPORTGATE128_OPEN 2'b10 `define S_TXPORTGATE128_CLOSED 2'b11 `timescale 1ns/1ns module tx_port_channel_gate_128 #( parameter C_DATA_WIDTH = 9'd128, // Local parameters parameter C_FIFO_DEPTH = 8, parameter C_FIFO_DATA_WIDTH = C_DATA_WIDTH+1 ) ( input RST, input RD_CLK, // FIFO read clock output [C_FIFO_DATA_WIDTH-1:0] RD_DATA, // FIFO read data output RD_EMPTY, // FIFO is empty input RD_EN, // FIFO read enable input CHNL_CLK, // Channel write clock input CHNL_TX, // Channel write receive signal output CHNL_TX_ACK, // Channel write acknowledgement signal input CHNL_TX_LAST, // Channel last write input [31:0] CHNL_TX_LEN, // Channel write length (in 32 bit words) input [30:0] CHNL_TX_OFF, // Channel write offset input [C_DATA_WIDTH-1:0] CHNL_TX_DATA, // Channel write data input CHNL_TX_DATA_VALID, // Channel write data valid output CHNL_TX_DATA_REN // Channel write data has been recieved ); (* syn_encoding = "user" *) (* fsm_encoding = "user" *) reg [1:0] rState=`S_TXPORTGATE128_IDLE, _rState=`S_TXPORTGATE128_IDLE; reg rFifoWen=0, _rFifoWen=0; reg [C_FIFO_DATA_WIDTH-1:0] rFifoData=0, _rFifoData=0; wire wFifoFull; reg rChnlTx=0, _rChnlTx=0; reg rChnlLast=0, _rChnlLast=0; reg [31:0] rChnlLen=0, _rChnlLen=0; reg [30:0] rChnlOff=0, _rChnlOff=0; reg rAck=0, _rAck=0; reg rPause=0, _rPause=0; reg rClosed=0, _rClosed=0; assign CHNL_TX_ACK = rAck; assign CHNL_TX_DATA_REN = (rState[1] & !rState[0] & !wFifoFull); // S_TXPORTGATE128_OPEN // Buffer the input signals that come from outside the tx_port. always @ (posedge CHNL_CLK) begin rChnlTx <= #1 (RST ? 1'd0 : _rChnlTx); rChnlLast <= #1 _rChnlLast; rChnlLen <= #1 _rChnlLen; rChnlOff <= #1 _rChnlOff; end always @ (*) begin _rChnlTx = CHNL_TX; _rChnlLast = CHNL_TX_LAST; _rChnlLen = CHNL_TX_LEN; _rChnlOff = CHNL_TX_OFF; end // FIFO for temporarily storing data from the channel. (* RAM_STYLE="DISTRIBUTED" *) async_fifo #(.C_WIDTH(C_FIFO_DATA_WIDTH), .C_DEPTH(C_FIFO_DEPTH)) fifo ( .WR_CLK(CHNL_CLK), .WR_RST(RST), .WR_EN(rFifoWen), .WR_DATA(rFifoData), .WR_FULL(wFifoFull), .RD_CLK(RD_CLK), .RD_RST(RST), .RD_EN(RD_EN), .RD_DATA(RD_DATA), .RD_EMPTY(RD_EMPTY) ); // Pass the transaction open event, transaction data, and the transaction // close event through to the RD_CLK domain via the async_fifo. always @ (posedge CHNL_CLK) begin rState <= #1 (RST ? `S_TXPORTGATE128_IDLE : _rState); rFifoWen <= #1 (RST ? 1'd0 : _rFifoWen); rFifoData <= #1 _rFifoData; rAck <= #1 (RST ? 1'd0 : _rAck); rPause <= #1 (RST ? 1'd0 : _rPause); rClosed <= #1 (RST ? 1'd0 : _rClosed); end always @ (*) begin _rState = rState; _rFifoWen = rFifoWen; _rFifoData = rFifoData; _rPause = rPause; _rAck = rAck; _rClosed = rClosed; case (rState) `S_TXPORTGATE128_IDLE: begin // Write the len, off, last _rPause = 0; _rClosed = 0; if (!wFifoFull) begin _rAck = rChnlTx; _rFifoWen = rChnlTx; _rFifoData = {1'd1, 64'd0, rChnlLen, rChnlOff, rChnlLast}; if (rChnlTx) _rState = `S_TXPORTGATE128_OPENING; end end `S_TXPORTGATE128_OPENING: begin // Write the len, off, last (again) _rAck = 0; _rClosed = (rClosed | !rChnlTx); if (!wFifoFull) begin if (rClosed | !rChnlTx) _rState = `S_TXPORTGATE128_CLOSED; else _rState = `S_TXPORTGATE128_OPEN; end end `S_TXPORTGATE128_OPEN: begin // Copy channel data into the FIFO if (!wFifoFull) begin _rFifoWen = CHNL_TX_DATA_VALID; // CHNL_TX_DATA_VALID & CHNL_TX_DATA should really be buffered _rFifoData = {1'd0, CHNL_TX_DATA}; // but the VALID+REN model seem to make this difficult. end if (!rChnlTx) _rState = `S_TXPORTGATE128_CLOSED; end `S_TXPORTGATE128_CLOSED: begin // Write the end marker (twice) if (!wFifoFull) begin _rPause = 1; _rFifoWen = 1; _rFifoData = {1'd1, {C_DATA_WIDTH{1'd0}}}; if (rPause) _rState = `S_TXPORTGATE128_IDLE; end end endcase end /* wire [35:0] wControl0; chipscope_icon_1 cs_icon( .CONTROL0(wControl0) ); chipscope_ila_t8_512 a0( .CLK(CHNL_CLK), .CONTROL(wControl0), .TRIG0({4'd0, wFifoFull, CHNL_TX, rState}), .DATA({313'd0, rChnlOff, // 31 rChnlLen, // 32 rChnlLast, // 1 rChnlTx, // 1 CHNL_TX_OFF, // 31 CHNL_TX_LEN, // 32 CHNL_TX_LAST, // 1 CHNL_TX, // 1 wFifoFull, // 1 rFifoData, // 65 rFifoWen, // 1 rState}) // 2 ); */ endmodule
///////////////////////////////////////////////////////////////////// //// //// //// pfpu32_f2i //// //// 32-bit floating point to integer converter //// //// //// //// Author: Andrey Bacherov //// //// [email protected] //// //// //// ///////////////////////////////////////////////////////////////////// //// //// //// Copyright (C) 2014 Andrey Bacherov //// //// [email protected] //// //// //// //// 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. //// //// //// ///////////////////////////////////////////////////////////////////// `include "mor1kx-defines.v" module pfpu32_f2i ( input clk, input rst, input flush_i, // flush pipe input adv_i, // advance pipe input start_i, // start conversion input signa_i, // input 'a' related values input [9:0] exp10a_i, input [23:0] fract24a_i, input snan_i, // 'a'/'b' related input qnan_i, output reg f2i_rdy_o, // f2i is ready output reg f2i_sign_o, // f2i signum output reg [23:0] f2i_int24_o, // f2i fractional output reg [4:0] f2i_shr_o, // f2i required shift right value output reg [3:0] f2i_shl_o, // f2i required shift left value output reg f2i_ovf_o, // f2i overflow flag output reg f2i_snan_o // f2i signaling NaN output reg ); /* Any stage's output is registered. Definitions: s??o_name - "S"tage number "??", "O"utput s??t_name - "S"tage number "??", "T"emporary (internally) */ // exponent after moving binary point at the end of mantissa // bias is also removed wire [9:0] s1t_exp10m = exp10a_i - 10'd150; // (- 127 - 23) // detect if now shift right is required wire [9:0] s1t_shr_t = {10{s1t_exp10m[9]}} & (10'd150 - exp10a_i); // limit right shift by 31 wire [4:0] s1t_shr = s1t_shr_t[4:0] | {5{|s1t_shr_t[9:5]}}; // detect if left shift required for mantissa // (limited by 15) wire [3:0] s1t_shl = {4{~s1t_exp10m[9]}} & (s1t_exp10m[3:0] | {4{|s1t_exp10m[9:4]}}); // check overflow wire s1t_is_shl_gt8 = s1t_shl[3] & (|s1t_shl[2:0]); wire s1t_is_shl_eq8 = s1t_shl[3] & (~(|s1t_shl[2:0])); wire s1t_is_shl_ovf = s1t_is_shl_gt8 | (s1t_is_shl_eq8 & (~signa_i)) | (s1t_is_shl_eq8 & signa_i & (|fract24a_i[22:0])); // registering output always @(posedge clk) begin if(adv_i) begin // input related f2i_snan_o <= snan_i; // computation related f2i_sign_o <= signa_i & (!(qnan_i | snan_i)); // if 'a' is a NaN than ouput is max. positive f2i_int24_o <= fract24a_i; f2i_shr_o <= s1t_shr; f2i_shl_o <= s1t_shl; f2i_ovf_o <= s1t_is_shl_ovf; end // (reset or flush) / advance end // posedge clock // ready is special case always @(posedge clk `OR_ASYNC_RST) begin if (rst) f2i_rdy_o <= 1'b0; else if(flush_i) f2i_rdy_o <= 1'b0; else if(adv_i) f2i_rdy_o <= start_i; end // posedge clock endmodule // pfpu32_f2i
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * 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. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // 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 REGENTS OF THE // UNIVERSITY OF CALIFORNIA 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. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: demux.v // Version: 1.00.a // Verilog Standard: Verilog-2001 // Description: A simple demultiplexer // Author: Dustin Richmond (@darichmond) //----------------------------------------------------------------------------- `timescale 1ns/1ns `include "functions.vh" module demux #( parameter C_OUTPUTS = 12, parameter C_WIDTH = 1 ) ( input [C_WIDTH-1:0] WR_DATA,// Inputs input [clog2s(C_OUTPUTS)-1:0] WR_SEL,// Selector output [C_OUTPUTS*C_WIDTH-1:0] RD_DATA// Outputs ); genvar i; reg [C_OUTPUTS*C_WIDTH-1:0] _rOut; assign RD_DATA = _rOut; always @(*) begin _rOut = 0; _rOut[C_WIDTH*WR_SEL +: C_WIDTH] = WR_DATA; end endmodule
/////////////////////////////////////////////////////////////////////////////// // // Company: Xilinx // Engineer: Jim Tatsukawa, Karl Kurbjun and Carl Ribbing // Sam Bobrowicz (Digilent Inc.) // Date: 5/30/2013 // Design Name: MMCME2 DRP // Module Name: mmcme2_drp.v // Version: 1.03 // Target Devices: 7 Series // Tool versions: 14.5 // Description: This calls the DRP register calculation functions and // provides a state machine to perform MMCM reconfiguration // based on the calulated values stored in a initialized // ROM. // // Revisions: 1/13/11 Updated ROM[18,41] LOCKED bitmask to 16'HFC00 // 5/30/13 Adding Fractional support for CLKFBOUT_MULT_F, CLKOUT0_DIVIDE_F // 2/02/14 (Digilent, Sam Bobrowicz) Modified to use values provided from a top // level to output CLK0 with runtime configurable frequency. Also added // parameter for controlling what the default output clock is (affecting // the automatically generated timing constraints). // // // Disclaimer: 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. // // (c) Copyright 2009-2010 Xilinx, Inc. // All rights reserved. // /////////////////////////////////////////////////////////////////////////////// `timescale 1ps/1ps module mmcme2_drp #( parameter DIV_F = 5 ) ( // These signals are controlled by user logic interface and are covered // in more detail within the XAPP. input SEN, input SCLK, input RST, output reg SRDY, input [35:0] S1_CLKOUT0, input [35:0] S1_CLKFBOUT, input [13:0] S1_DIVCLK, input [39:0] S1_LOCK, input [9:0] S1_DIGITAL_FILT, input REF_CLK, output PXL_CLK, output CLKFBOUT_O, input CLKFBOUT_I, output LOCKED_O ); // 100 ps delay for behavioral simulations localparam TCQ = 100; wire [38:0] rom [12:0]; // 39 bit word 13 words deep array of reg writes to perform (no longer a ROM) reg [3:0] rom_addr; reg [38:0] rom_do; reg next_srdy; reg [3:0] next_rom_addr; reg [6:0] next_daddr; reg next_dwe; reg next_den; reg next_rst_mmcm; reg [15:0] next_di; // These signals are to be connected to the MMCM_ADV by port name. // Their use matches the MMCM port description in the Device User Guide. wire [15:0] DO; wire DRDY; wire LOCKED; reg DWE; reg DEN; reg [6:0] DADDR; reg [15:0] DI; wire DCLK; reg RST_MMCM; // Pass SCLK to DCLK for the MMCM assign DCLK = SCLK; // rom entries contain (in order) the address, a bitmask, and a bitset //*********************************************************************** // State 1 Initialization //*********************************************************************** // Store the power bits assign rom[0] = {7'h28, 16'h0000, 16'hFFFF}; // Store CLKOUT0 divide and phase assign rom[1] = {7'h08, 16'h1000, S1_CLKOUT0[15:0]}; assign rom[2] = {7'h09, 16'h8000, S1_CLKOUT0[31:16]}; // Store CLKOUT0 additional frac values assign rom[3] = {7'h07, 16'hC3FF, 2'b00 , S1_CLKOUT0[35:32], 10'h000}; // Store CLKFBOUT additional frac values assign rom[4] = {7'h13, 16'hC3FF, 2'b00 , S1_CLKFBOUT[35:32], 10'h000}; // Store the input divider assign rom[5] = {7'h16, 16'hC000, {2'h0, S1_DIVCLK[13:0]} }; // Store CLKFBOUT divide and phase assign rom[6] = {7'h14, 16'h1000, S1_CLKFBOUT[15:0]}; assign rom[7] = {7'h15, 16'h8000, S1_CLKFBOUT[31:16]}; // Store the lock settings assign rom[8] = {7'h18, 16'hFC00, {6'h00, S1_LOCK[29:20]} }; assign rom[9] = {7'h19, 16'h8000, {1'b0 , S1_LOCK[34:30], S1_LOCK[9:0]} }; assign rom[10] = {7'h1A, 16'h8000, {1'b0 , S1_LOCK[39:35], S1_LOCK[19:10]} }; // Store the filter settings assign rom[11] = {7'h4E, 16'h66FF, S1_DIGITAL_FILT[9], 2'h0, S1_DIGITAL_FILT[8:7], 2'h0, S1_DIGITAL_FILT[6], 8'h00 }; assign rom[12] = {7'h4F, 16'h666F, S1_DIGITAL_FILT[5], 2'h0, S1_DIGITAL_FILT[4:3], 2'h0, S1_DIGITAL_FILT[2:1], 2'h0, S1_DIGITAL_FILT[0], 4'h0 }; // Output the initialized rom value based on rom_addr each clock cycle always @(posedge SCLK) begin rom_do<= #TCQ rom[rom_addr]; end //************************************************************************** // Everything below is associated whith the state machine that is used to // Read/Modify/Write to the MMCM. //************************************************************************** // State Definitions localparam RESTART = 4'h1; localparam WAIT_LOCK = 4'h2; localparam WAIT_SEN = 4'h3; localparam ADDRESS = 4'h4; localparam WAIT_A_DRDY = 4'h5; localparam BITMASK = 4'h6; localparam BITSET = 4'h7; localparam WRITE = 4'h8; localparam WAIT_DRDY = 4'h9; // State sync reg [3:0] current_state = RESTART; reg [3:0] next_state = RESTART; // These variables are used to keep track of the number of iterations that // each state takes to reconfigure. // STATE_COUNT_CONST is used to reset the counters and should match the // number of registers necessary to reconfigure each state. localparam STATE_COUNT_CONST = 13; reg [3:0] state_count = STATE_COUNT_CONST; reg [3:0] next_state_count = STATE_COUNT_CONST; // This block assigns the next register value from the state machine below always @(posedge SCLK) begin DADDR <= #TCQ next_daddr; DWE <= #TCQ next_dwe; DEN <= #TCQ next_den; RST_MMCM <= #TCQ next_rst_mmcm; DI <= #TCQ next_di; SRDY <= #TCQ next_srdy; rom_addr <= #TCQ next_rom_addr; state_count <= #TCQ next_state_count; end // This block assigns the next state, reset is syncronous. always @(posedge SCLK) begin if(RST) begin current_state <= #TCQ RESTART; end else begin current_state <= #TCQ next_state; end end always @* begin // Setup the default values next_srdy = 1'b0; next_daddr = DADDR; next_dwe = 1'b0; next_den = 1'b0; next_rst_mmcm = RST_MMCM; next_di = DI; next_rom_addr = rom_addr; next_state_count = state_count; case (current_state) // If RST is asserted reset the machine RESTART: begin next_daddr = 7'h00; next_di = 16'h0000; next_rom_addr = 6'h00; next_rst_mmcm = 1'b1; next_state = WAIT_LOCK; end // Waits for the MMCM to assert LOCKED - once it does asserts SRDY WAIT_LOCK: begin // Make sure reset is de-asserted next_rst_mmcm = 1'b0; // Reset the number of registers left to write for the next // reconfiguration event. next_state_count = STATE_COUNT_CONST ; if(LOCKED) begin // MMCM is locked, go on to wait for the SEN signal next_state = WAIT_SEN; // Assert SRDY to indicate that the reconfiguration module is // ready next_srdy = 1'b1; end else begin // Keep waiting, locked has not asserted yet next_state = WAIT_LOCK; end end // Wait for the next SEN pulse and set the ROM addr appropriately WAIT_SEN: begin if (SEN) begin // SEN was asserted next_rom_addr = 8'h00; // Go on to address the MMCM next_state = ADDRESS; end else begin // Keep waiting for SEN to be asserted next_state = WAIT_SEN; end end // Set the address on the MMCM and assert DEN to read the value ADDRESS: begin // Reset the DCM through the reconfiguration next_rst_mmcm = 1'b1; // Enable a read from the MMCM and set the MMCM address next_den = 1'b1; next_daddr = rom_do[38:32]; // Wait for the data to be ready next_state = WAIT_A_DRDY; end // Wait for DRDY to assert after addressing the MMCM WAIT_A_DRDY: begin if (DRDY) begin // Data is ready, mask out the bits to save next_state = BITMASK; end else begin // Keep waiting till data is ready next_state = WAIT_A_DRDY; end end // Zero out the bits that are not set in the mask stored in rom BITMASK: begin // Do the mask next_di = rom_do[31:16] & DO; // Go on to set the bits next_state = BITSET; end // After the input is masked, OR the bits with calculated value in rom BITSET: begin // Set the bits that need to be assigned next_di = rom_do[15:0] | DI; // Set the next address to read from ROM next_rom_addr = rom_addr + 1'b1; // Go on to write the data to the MMCM next_state = WRITE; end // DI is setup so assert DWE, DEN, and RST_MMCM. Subtract one from the // state count and go to wait for DRDY. WRITE: begin // Set WE and EN on MMCM next_dwe = 1'b1; next_den = 1'b1; // Decrement the number of registers left to write next_state_count = state_count - 1'b1; // Wait for the write to complete next_state = WAIT_DRDY; end // Wait for DRDY to assert from the MMCM. If the state count is not 0 // jump to ADDRESS (continue reconfiguration). If state count is // 0 wait for lock. WAIT_DRDY: begin if(DRDY) begin // Write is complete if(state_count > 0) begin // If there are more registers to write keep going next_state = ADDRESS; end else begin // There are no more registers to write so wait for the MMCM // to lock next_state = WAIT_LOCK; end end else begin // Keep waiting for write to complete next_state = WAIT_DRDY; end end // If in an unknown state reset the machine default: begin next_state = RESTART; end endcase end ////////////////////////////////////////////////////////////////////////////////////// ///////// MMCM Instantiation /////////// ////////////////////////////////////////////////////////////////////////////////////// // Clocking primitive //------------------------------------ // Instantiation of the MMCM primitive // * Unused inputs are tied off // * Unused outputs are labeled unused wire psdone_unused; wire clkfboutb_unused; wire clkout0b_unused; wire clkout1_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 #(.BANDWIDTH ("OPTIMIZED"), .CLKOUT4_CASCADE ("FALSE"), .COMPENSATION ("ZHOLD"), .STARTUP_WAIT ("FALSE"), .DIVCLK_DIVIDE (1), .CLKFBOUT_MULT_F (10.000), .CLKFBOUT_PHASE (0.000), .CLKFBOUT_USE_FINE_PS ("FALSE"), .CLKOUT0_DIVIDE_F (DIV_F), .CLKOUT0_PHASE (0.000), .CLKOUT0_DUTY_CYCLE (0.500), .CLKOUT0_USE_FINE_PS ("FALSE"), .CLKIN1_PERIOD (10.000), .REF_JITTER1 (0.010)) mmcm_adv_inst // Output clocks (.CLKFBOUT (CLKFBOUT_O), .CLKFBOUTB (clkfboutb_unused), .CLKOUT0 (PXL_CLK), .CLKOUT0B (clkout0b_unused), .CLKOUT1 (clkout1_unused), .CLKOUT1B (clkout1b_unused), .CLKOUT2 (clkout2_unused), .CLKOUT2B (clkout2b_unused), .CLKOUT3 (clkout3_unused), .CLKOUT3B (clkout3b_unused), .CLKOUT4 (clkout4_unused), .CLKOUT5 (clkout5_unused), .CLKOUT6 (clkout6_unused), // Input clock control .CLKFBIN (CLKFBOUT_I), .CLKIN1 (REF_CLK), .CLKIN2 (1'b0), // Tied to always select the primary input clock .CLKINSEL (1'b1), // Ports for dynamic reconfiguration .DADDR (DADDR), .DCLK (DCLK), .DEN (DEN), .DI (DI), .DO (DO), .DRDY (DRDY), .DWE (DWE), // Ports for dynamic phase shift .PSCLK (1'b0), .PSEN (1'b0), .PSINCDEC (1'b0), .PSDONE (psdone_unused), // Other control and status signals .LOCKED (LOCKED), .CLKINSTOPPED (clkinstopped_unused), .CLKFBSTOPPED (clkfbstopped_unused), .PWRDWN (1'b0), .RST (RST_MMCM)); assign LOCKED_O = LOCKED; endmodule
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * 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. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // 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 REGENTS OF THE // UNIVERSITY OF CALIFORNIA 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. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: tx_port_channel_gate_32.v // Version: 1.00.a // Verilog Standard: Verilog-2001 // Description: Captures transaction open/close events as well as data // and passes it to the RD_CLK domain through the async_fifo. CHNL_TX_DATA_REN can // only be high after CHNL_TX goes high and after the CHNL_TX_ACK pulse. When // CHNL_TX drops, the channel closes (until the next transaction -- signaled by // CHNL_TX going up again). // Author: Matt Jacobsen // History: @mattj: Version 2.0 //----------------------------------------------------------------------------- `define S_TXPORTGATE32_IDLE 2'b00 `define S_TXPORTGATE32_OPENING 2'b01 `define S_TXPORTGATE32_OPEN 2'b10 `define S_TXPORTGATE32_CLOSED 2'b11 `timescale 1ns/1ns module tx_port_channel_gate_32 #( parameter C_DATA_WIDTH = 9'd32, // Local parameters parameter C_FIFO_DEPTH = 8, parameter C_FIFO_DATA_WIDTH = C_DATA_WIDTH+1 ) ( input RST, input RD_CLK, // FIFO read clock output [C_FIFO_DATA_WIDTH-1:0] RD_DATA, // FIFO read data output RD_EMPTY, // FIFO is empty input RD_EN, // FIFO read enable input CHNL_CLK, // Channel write clock input CHNL_TX, // Channel write receive signal output CHNL_TX_ACK, // Channel write acknowledgement signal input CHNL_TX_LAST, // Channel last write input [31:0] CHNL_TX_LEN, // Channel write length (in 32 bit words) input [30:0] CHNL_TX_OFF, // Channel write offset input [C_DATA_WIDTH-1:0] CHNL_TX_DATA, // Channel write data input CHNL_TX_DATA_VALID, // Channel write data valid output CHNL_TX_DATA_REN // Channel write data has been recieved ); (* syn_encoding = "user" *) (* fsm_encoding = "user" *) reg [1:0] rState=`S_TXPORTGATE32_IDLE, _rState=`S_TXPORTGATE32_IDLE; reg rFifoWen=0, _rFifoWen=0; reg [C_FIFO_DATA_WIDTH-1:0] rFifoData=0, _rFifoData=0; wire wFifoFull; reg rChnlTx=0, _rChnlTx=0; reg rChnlLast=0, _rChnlLast=0; reg [31:0] rChnlLen=0, _rChnlLen=0; reg [30:0] rChnlOff=0, _rChnlOff=0; reg rAck=0, _rAck=0; reg rPause=0, _rPause=0; reg rClosed=0, _rClosed=0; assign CHNL_TX_ACK = rAck; assign CHNL_TX_DATA_REN = (rState[1] & !rState[0] & !wFifoFull); // S_TXPORTGATE32_OPEN // Buffer the input signals that come from outside the tx_port. always @ (posedge CHNL_CLK) begin rChnlTx <= #1 (RST ? 1'd0 : _rChnlTx); rChnlLast <= #1 _rChnlLast; rChnlLen <= #1 _rChnlLen; rChnlOff <= #1 _rChnlOff; end always @ (*) begin _rChnlTx = CHNL_TX; _rChnlLast = CHNL_TX_LAST; _rChnlLen = CHNL_TX_LEN; _rChnlOff = CHNL_TX_OFF; end // FIFO for temporarily storing data from the channel. (* RAM_STYLE="DISTRIBUTED" *) async_fifo #(.C_WIDTH(C_FIFO_DATA_WIDTH), .C_DEPTH(C_FIFO_DEPTH)) fifo ( .WR_CLK(CHNL_CLK), .WR_RST(RST), .WR_EN(rFifoWen), .WR_DATA(rFifoData), .WR_FULL(wFifoFull), .RD_CLK(RD_CLK), .RD_RST(RST), .RD_EN(RD_EN), .RD_DATA(RD_DATA), .RD_EMPTY(RD_EMPTY) ); // Pass the transaction open event, transaction data, and the transaction // close event through to the RD_CLK domain via the async_fifo. always @ (posedge CHNL_CLK) begin rState <= #1 (RST ? `S_TXPORTGATE32_IDLE : _rState); rFifoWen <= #1 (RST ? 1'd0 : _rFifoWen); rFifoData <= #1 _rFifoData; rAck <= #1 (RST ? 1'd0 : _rAck); rPause <= #1 (RST ? 1'd0 : _rPause); rClosed <= #1 (RST ? 1'd0 : _rClosed); end always @ (*) begin _rState = rState; _rFifoWen = rFifoWen; _rFifoData = rFifoData; _rPause = rPause; _rAck = rAck; _rClosed = rClosed; case (rState) `S_TXPORTGATE32_IDLE: begin // Write the len _rPause = 0; _rClosed = 0; if (!wFifoFull) begin _rFifoWen = rChnlTx; _rFifoData = {1'd1, rChnlLen}; if (rChnlTx) _rState = `S_TXPORTGATE32_OPENING; end end `S_TXPORTGATE32_OPENING: begin // Write the off, last _rClosed = (rClosed | !rChnlTx); if (!wFifoFull) begin _rAck = rChnlTx; _rFifoData = {1'd1, rChnlOff, rChnlLast}; if (rClosed | !rChnlTx) _rState = `S_TXPORTGATE32_CLOSED; else _rState = `S_TXPORTGATE32_OPEN; end end `S_TXPORTGATE32_OPEN: begin // Copy channel data into the FIFO _rAck = 0; if (!wFifoFull) begin _rFifoWen = CHNL_TX_DATA_VALID; // CHNL_TX_DATA_VALID & CHNL_TX_DATA should really be buffered _rFifoData = {1'd0, CHNL_TX_DATA}; // but the VALID+REN model seem to make this difficult. end if (!rChnlTx) _rState = `S_TXPORTGATE32_CLOSED; end `S_TXPORTGATE32_CLOSED: begin // Write the end marker (twice) _rAck = 0; if (!wFifoFull) begin _rPause = 1; _rFifoWen = 1; _rFifoData = {1'd1, {C_DATA_WIDTH{1'd0}}}; if (rPause) _rState = `S_TXPORTGATE32_IDLE; end end endcase end /* wire [35:0] wControl0; chipscope_icon_1 cs_icon( .CONTROL0(wControl0) ); chipscope_ila_t8_512 a0( .CLK(CHNL_CLK), .CONTROL(wControl0), .TRIG0({4'd0, wFifoFull, CHNL_TX, rState}), .DATA({313'd0, rChnlOff, // 31 rChnlLen, // 32 rChnlLast, // 1 rChnlTx, // 1 CHNL_TX_OFF, // 31 CHNL_TX_LEN, // 32 CHNL_TX_LAST, // 1 CHNL_TX, // 1 wFifoFull, // 1 rFifoData, // 65 rFifoWen, // 1 rState}) // 2 ); */ endmodule
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * 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. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // 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 REGENTS OF THE // UNIVERSITY OF CALIFORNIA 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. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: tx_port_channel_gate_32.v // Version: 1.00.a // Verilog Standard: Verilog-2001 // Description: Captures transaction open/close events as well as data // and passes it to the RD_CLK domain through the async_fifo. CHNL_TX_DATA_REN can // only be high after CHNL_TX goes high and after the CHNL_TX_ACK pulse. When // CHNL_TX drops, the channel closes (until the next transaction -- signaled by // CHNL_TX going up again). // Author: Matt Jacobsen // History: @mattj: Version 2.0 //----------------------------------------------------------------------------- `define S_TXPORTGATE32_IDLE 2'b00 `define S_TXPORTGATE32_OPENING 2'b01 `define S_TXPORTGATE32_OPEN 2'b10 `define S_TXPORTGATE32_CLOSED 2'b11 `timescale 1ns/1ns module tx_port_channel_gate_32 #( parameter C_DATA_WIDTH = 9'd32, // Local parameters parameter C_FIFO_DEPTH = 8, parameter C_FIFO_DATA_WIDTH = C_DATA_WIDTH+1 ) ( input RST, input RD_CLK, // FIFO read clock output [C_FIFO_DATA_WIDTH-1:0] RD_DATA, // FIFO read data output RD_EMPTY, // FIFO is empty input RD_EN, // FIFO read enable input CHNL_CLK, // Channel write clock input CHNL_TX, // Channel write receive signal output CHNL_TX_ACK, // Channel write acknowledgement signal input CHNL_TX_LAST, // Channel last write input [31:0] CHNL_TX_LEN, // Channel write length (in 32 bit words) input [30:0] CHNL_TX_OFF, // Channel write offset input [C_DATA_WIDTH-1:0] CHNL_TX_DATA, // Channel write data input CHNL_TX_DATA_VALID, // Channel write data valid output CHNL_TX_DATA_REN // Channel write data has been recieved ); (* syn_encoding = "user" *) (* fsm_encoding = "user" *) reg [1:0] rState=`S_TXPORTGATE32_IDLE, _rState=`S_TXPORTGATE32_IDLE; reg rFifoWen=0, _rFifoWen=0; reg [C_FIFO_DATA_WIDTH-1:0] rFifoData=0, _rFifoData=0; wire wFifoFull; reg rChnlTx=0, _rChnlTx=0; reg rChnlLast=0, _rChnlLast=0; reg [31:0] rChnlLen=0, _rChnlLen=0; reg [30:0] rChnlOff=0, _rChnlOff=0; reg rAck=0, _rAck=0; reg rPause=0, _rPause=0; reg rClosed=0, _rClosed=0; assign CHNL_TX_ACK = rAck; assign CHNL_TX_DATA_REN = (rState[1] & !rState[0] & !wFifoFull); // S_TXPORTGATE32_OPEN // Buffer the input signals that come from outside the tx_port. always @ (posedge CHNL_CLK) begin rChnlTx <= #1 (RST ? 1'd0 : _rChnlTx); rChnlLast <= #1 _rChnlLast; rChnlLen <= #1 _rChnlLen; rChnlOff <= #1 _rChnlOff; end always @ (*) begin _rChnlTx = CHNL_TX; _rChnlLast = CHNL_TX_LAST; _rChnlLen = CHNL_TX_LEN; _rChnlOff = CHNL_TX_OFF; end // FIFO for temporarily storing data from the channel. (* RAM_STYLE="DISTRIBUTED" *) async_fifo #(.C_WIDTH(C_FIFO_DATA_WIDTH), .C_DEPTH(C_FIFO_DEPTH)) fifo ( .WR_CLK(CHNL_CLK), .WR_RST(RST), .WR_EN(rFifoWen), .WR_DATA(rFifoData), .WR_FULL(wFifoFull), .RD_CLK(RD_CLK), .RD_RST(RST), .RD_EN(RD_EN), .RD_DATA(RD_DATA), .RD_EMPTY(RD_EMPTY) ); // Pass the transaction open event, transaction data, and the transaction // close event through to the RD_CLK domain via the async_fifo. always @ (posedge CHNL_CLK) begin rState <= #1 (RST ? `S_TXPORTGATE32_IDLE : _rState); rFifoWen <= #1 (RST ? 1'd0 : _rFifoWen); rFifoData <= #1 _rFifoData; rAck <= #1 (RST ? 1'd0 : _rAck); rPause <= #1 (RST ? 1'd0 : _rPause); rClosed <= #1 (RST ? 1'd0 : _rClosed); end always @ (*) begin _rState = rState; _rFifoWen = rFifoWen; _rFifoData = rFifoData; _rPause = rPause; _rAck = rAck; _rClosed = rClosed; case (rState) `S_TXPORTGATE32_IDLE: begin // Write the len _rPause = 0; _rClosed = 0; if (!wFifoFull) begin _rFifoWen = rChnlTx; _rFifoData = {1'd1, rChnlLen}; if (rChnlTx) _rState = `S_TXPORTGATE32_OPENING; end end `S_TXPORTGATE32_OPENING: begin // Write the off, last _rClosed = (rClosed | !rChnlTx); if (!wFifoFull) begin _rAck = rChnlTx; _rFifoData = {1'd1, rChnlOff, rChnlLast}; if (rClosed | !rChnlTx) _rState = `S_TXPORTGATE32_CLOSED; else _rState = `S_TXPORTGATE32_OPEN; end end `S_TXPORTGATE32_OPEN: begin // Copy channel data into the FIFO _rAck = 0; if (!wFifoFull) begin _rFifoWen = CHNL_TX_DATA_VALID; // CHNL_TX_DATA_VALID & CHNL_TX_DATA should really be buffered _rFifoData = {1'd0, CHNL_TX_DATA}; // but the VALID+REN model seem to make this difficult. end if (!rChnlTx) _rState = `S_TXPORTGATE32_CLOSED; end `S_TXPORTGATE32_CLOSED: begin // Write the end marker (twice) _rAck = 0; if (!wFifoFull) begin _rPause = 1; _rFifoWen = 1; _rFifoData = {1'd1, {C_DATA_WIDTH{1'd0}}}; if (rPause) _rState = `S_TXPORTGATE32_IDLE; end end endcase end /* wire [35:0] wControl0; chipscope_icon_1 cs_icon( .CONTROL0(wControl0) ); chipscope_ila_t8_512 a0( .CLK(CHNL_CLK), .CONTROL(wControl0), .TRIG0({4'd0, wFifoFull, CHNL_TX, rState}), .DATA({313'd0, rChnlOff, // 31 rChnlLen, // 32 rChnlLast, // 1 rChnlTx, // 1 CHNL_TX_OFF, // 31 CHNL_TX_LEN, // 32 CHNL_TX_LAST, // 1 CHNL_TX, // 1 wFifoFull, // 1 rFifoData, // 65 rFifoWen, // 1 rState}) // 2 ); */ endmodule
`timescale 1ns / 1ps ////////////////////////////////////////////////////////////////////////////////// // Company: // Engineer: // // Create Date: 10:50:10 11/03/2014 // Design Name: // Module Name: Output_2_Disp // Project Name: // Target Devices: // Tool versions: // Description: // // Dependencies: // // Revision: // Revision 0.01 - File Created // Additional Comments: // ////////////////////////////////////////////////////////////////////////////////// module Multi_8CH32(input clk, input rst, input EN, //Write EN input[2:0]Test, //ALU&Clock,SW[7:5] input[63:0]point_in, //Õë¶Ô8λÏÔʾÊäÈë¸÷8¸öСÊýµã input[63:0]LES, //Õë¶Ô8λÏÔʾÊäÈë¸÷8¸öÉÁ˸λ input[31:0] Data0, //disp_cpudata input[31:0] data1, input[31:0] data2, input[31:0] data3, input[31:0] data4, input[31:0] data5, input[31:0] data6, input[31:0] data7, output [7:0] point_out, output [7:0] LE_out, output [31:0]Disp_num ); endmodule
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * 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. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // 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 REGENTS OF THE // UNIVERSITY OF CALIFORNIA 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. // ---------------------------------------------------------------------- // ---------------------------------------------------------------------- // Filename: Filename: tx_multiplexer.v // Version: Version: 1.0 // Verilog Standard: Verilog-2005 // Description: the TX Multiplexer services read and write requests from // RIFFA channels in round robin order. // Author: Dustin Richmond (@darichmond) // ---------------------------------------------------------------------- `include "trellis.vh" module tx_multiplexer #( parameter C_PCI_DATA_WIDTH = 128, parameter C_NUM_CHNL = 12, parameter C_TAG_WIDTH = 5, parameter C_VENDOR = "ALTERA", parameter C_DEPTH_PACKETS = 10 ) ( input CLK, input RST_IN, input [C_NUM_CHNL-1:0] WR_REQ, // Write request input [(C_NUM_CHNL*`SIG_ADDR_W)-1:0] WR_ADDR, // Write address input [(C_NUM_CHNL*`SIG_LEN_W)-1:0] WR_LEN, // Write data length input [(C_NUM_CHNL*C_PCI_DATA_WIDTH)-1:0] WR_DATA, // Write data output [C_NUM_CHNL-1:0] WR_DATA_REN, // Write data read enable output [C_NUM_CHNL-1:0] WR_ACK, // Write request has been accepted output [C_NUM_CHNL-1:0] WR_SENT, // Write Reuqest has been sent to the core input [C_NUM_CHNL-1:0] RD_REQ, // Read request input [(C_NUM_CHNL*2)-1:0] RD_SG_CHNL, // Read request channel for scatter gather lists input [(C_NUM_CHNL*`SIG_ADDR_W)-1:0] RD_ADDR, // Read request address input [(C_NUM_CHNL*`SIG_LEN_W)-1:0] RD_LEN, // Read request length output [C_NUM_CHNL-1:0] RD_ACK, // Read request has been accepted output [5:0] INT_TAG, // Internal tag to exchange with external output INT_TAG_VALID, // High to signal tag exchange input [C_TAG_WIDTH-1:0] EXT_TAG, // External tag to provide in exchange for internal tag input EXT_TAG_VALID, // High to signal external tag is valid output TX_ENG_RD_REQ_SENT, // Read completion request issued input RXBUF_SPACE_AVAIL, // Interface: TXR Engine output TXR_DATA_VALID, output [C_PCI_DATA_WIDTH-1:0] TXR_DATA, output TXR_DATA_START_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] TXR_DATA_START_OFFSET, output TXR_DATA_END_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] TXR_DATA_END_OFFSET, input TXR_DATA_READY, output TXR_META_VALID, output [`SIG_FBE_W-1:0] TXR_META_FDWBE, output [`SIG_LBE_W-1:0] TXR_META_LDWBE, output [`SIG_ADDR_W-1:0] TXR_META_ADDR, output [`SIG_LEN_W-1:0] TXR_META_LENGTH, output [`SIG_TAG_W-1:0] TXR_META_TAG, output [`SIG_TC_W-1:0] TXR_META_TC, output [`SIG_ATTR_W-1:0] TXR_META_ATTR, output [`SIG_TYPE_W-1:0] TXR_META_TYPE, output TXR_META_EP, input TXR_META_READY, input TXR_SENT); wire [C_NUM_CHNL-1:0] wAckRdData; wire wAckValid; reg [C_NUM_CHNL-1:0] rAckWrData; // Registered fifo input (only write acks) reg [C_NUM_CHNL-1:0] rAckRdData; // Registered fifo output (only write acks) reg rAckWrEn,_rAckWrEn; // Fifo write enable (RD or WR_ACK) reg rAckRdEn; // Fifo read enable (TXR_SENT) always @(*) begin _rAckWrEn = (WR_ACK != 0) | (RD_ACK != 0); end always @(posedge CLK) begin rAckWrData <= WR_ACK; rAckWrEn <= _rAckWrEn; end always @(posedge CLK) begin rAckRdEn <= TXR_SENT; if(rAckRdEn & wAckValid) begin rAckRdData <= wAckRdData;// end else begin rAckRdData <= 0; end end assign WR_SENT = rAckRdData; fifo #(// Parameters .C_WIDTH (C_NUM_CHNL), .C_DEPTH (C_DEPTH_PACKETS*8), // This is an extremely conservative estimate... .C_DELAY (0) /*AUTOINSTPARAM*/) req_ack_fifo (// Outputs .WR_READY (), .RD_DATA (wAckRdData), .RD_VALID (wAckValid), // Inputs .WR_DATA (rAckWrData), .WR_VALID (rAckWrEn), .RD_READY (rAckRdEn), .RST (RST_IN), /*AUTOINST*/ // Inputs .CLK (CLK)); generate if(C_PCI_DATA_WIDTH == 32) begin tx_multiplexer_32 #(/*AUTOINSTPARAM*/ // Parameters .C_PCI_DATA_WIDTH (C_PCI_DATA_WIDTH), .C_NUM_CHNL (C_NUM_CHNL), .C_TAG_WIDTH (C_TAG_WIDTH), .C_VENDOR (C_VENDOR)) tx_mux (/*AUTOINST*/ // Outputs .WR_DATA_REN (WR_DATA_REN[C_NUM_CHNL-1:0]), .WR_ACK (WR_ACK[C_NUM_CHNL-1:0]), .RD_ACK (RD_ACK[C_NUM_CHNL-1:0]), .INT_TAG (INT_TAG[5:0]), .INT_TAG_VALID (INT_TAG_VALID), .TX_ENG_RD_REQ_SENT (TX_ENG_RD_REQ_SENT), .TXR_DATA_VALID (TXR_DATA_VALID), .TXR_DATA (TXR_DATA[C_PCI_DATA_WIDTH-1:0]), .TXR_DATA_START_FLAG (TXR_DATA_START_FLAG), .TXR_DATA_START_OFFSET (TXR_DATA_START_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .TXR_DATA_END_FLAG (TXR_DATA_END_FLAG), .TXR_DATA_END_OFFSET (TXR_DATA_END_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .TXR_META_VALID (TXR_META_VALID), .TXR_META_FDWBE (TXR_META_FDWBE[`SIG_FBE_W-1:0]), .TXR_META_LDWBE (TXR_META_LDWBE[`SIG_LBE_W-1:0]), .TXR_META_ADDR (TXR_META_ADDR[`SIG_ADDR_W-1:0]), .TXR_META_LENGTH (TXR_META_LENGTH[`SIG_LEN_W-1:0]), .TXR_META_TAG (TXR_META_TAG[`SIG_TAG_W-1:0]), .TXR_META_TC (TXR_META_TC[`SIG_TC_W-1:0]), .TXR_META_ATTR (TXR_META_ATTR[`SIG_ATTR_W-1:0]), .TXR_META_TYPE (TXR_META_TYPE[`SIG_TYPE_W-1:0]), .TXR_META_EP (TXR_META_EP), // Inputs .CLK (CLK), .RST_IN (RST_IN), .WR_REQ (WR_REQ[C_NUM_CHNL-1:0]), .WR_ADDR (WR_ADDR[(C_NUM_CHNL*`SIG_ADDR_W)-1:0]), .WR_LEN (WR_LEN[(C_NUM_CHNL*`SIG_LEN_W)-1:0]), .WR_DATA (WR_DATA[(C_NUM_CHNL*C_PCI_DATA_WIDTH)-1:0]), .RD_REQ (RD_REQ[C_NUM_CHNL-1:0]), .RD_SG_CHNL (RD_SG_CHNL[(C_NUM_CHNL*2)-1:0]), .RD_ADDR (RD_ADDR[(C_NUM_CHNL*`SIG_ADDR_W)-1:0]), .RD_LEN (RD_LEN[(C_NUM_CHNL*`SIG_LEN_W)-1:0]), .EXT_TAG (EXT_TAG[C_TAG_WIDTH-1:0]), .EXT_TAG_VALID (EXT_TAG_VALID), .RXBUF_SPACE_AVAIL (RXBUF_SPACE_AVAIL), .TXR_DATA_READY (TXR_DATA_READY), .TXR_META_READY (TXR_META_READY)); end else if(C_PCI_DATA_WIDTH == 64) begin tx_multiplexer_64 #(/*AUTOINSTPARAM*/ // Parameters .C_PCI_DATA_WIDTH (C_PCI_DATA_WIDTH), .C_NUM_CHNL (C_NUM_CHNL), .C_TAG_WIDTH (C_TAG_WIDTH), .C_VENDOR (C_VENDOR)) tx_mux (/*AUTOINST*/ // Outputs .WR_DATA_REN (WR_DATA_REN[C_NUM_CHNL-1:0]), .WR_ACK (WR_ACK[C_NUM_CHNL-1:0]), .RD_ACK (RD_ACK[C_NUM_CHNL-1:0]), .INT_TAG (INT_TAG[5:0]), .INT_TAG_VALID (INT_TAG_VALID), .TX_ENG_RD_REQ_SENT (TX_ENG_RD_REQ_SENT), .TXR_DATA_VALID (TXR_DATA_VALID), .TXR_DATA (TXR_DATA[C_PCI_DATA_WIDTH-1:0]), .TXR_DATA_START_FLAG (TXR_DATA_START_FLAG), .TXR_DATA_START_OFFSET (TXR_DATA_START_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .TXR_DATA_END_FLAG (TXR_DATA_END_FLAG), .TXR_DATA_END_OFFSET (TXR_DATA_END_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .TXR_META_VALID (TXR_META_VALID), .TXR_META_FDWBE (TXR_META_FDWBE[`SIG_FBE_W-1:0]), .TXR_META_LDWBE (TXR_META_LDWBE[`SIG_LBE_W-1:0]), .TXR_META_ADDR (TXR_META_ADDR[`SIG_ADDR_W-1:0]), .TXR_META_LENGTH (TXR_META_LENGTH[`SIG_LEN_W-1:0]), .TXR_META_TAG (TXR_META_TAG[`SIG_TAG_W-1:0]), .TXR_META_TC (TXR_META_TC[`SIG_TC_W-1:0]), .TXR_META_ATTR (TXR_META_ATTR[`SIG_ATTR_W-1:0]), .TXR_META_TYPE (TXR_META_TYPE[`SIG_TYPE_W-1:0]), .TXR_META_EP (TXR_META_EP), // Inputs .CLK (CLK), .RST_IN (RST_IN), .WR_REQ (WR_REQ[C_NUM_CHNL-1:0]), .WR_ADDR (WR_ADDR[(C_NUM_CHNL*`SIG_ADDR_W)-1:0]), .WR_LEN (WR_LEN[(C_NUM_CHNL*`SIG_LEN_W)-1:0]), .WR_DATA (WR_DATA[(C_NUM_CHNL*C_PCI_DATA_WIDTH)-1:0]), .RD_REQ (RD_REQ[C_NUM_CHNL-1:0]), .RD_SG_CHNL (RD_SG_CHNL[(C_NUM_CHNL*2)-1:0]), .RD_ADDR (RD_ADDR[(C_NUM_CHNL*`SIG_ADDR_W)-1:0]), .RD_LEN (RD_LEN[(C_NUM_CHNL*`SIG_LEN_W)-1:0]), .EXT_TAG (EXT_TAG[C_TAG_WIDTH-1:0]), .EXT_TAG_VALID (EXT_TAG_VALID), .RXBUF_SPACE_AVAIL (RXBUF_SPACE_AVAIL), .TXR_DATA_READY (TXR_DATA_READY), .TXR_META_READY (TXR_META_READY)); end else if(C_PCI_DATA_WIDTH == 128) begin tx_multiplexer_128 #(/*AUTOINSTPARAM*/ // Parameters .C_PCI_DATA_WIDTH (C_PCI_DATA_WIDTH), .C_NUM_CHNL (C_NUM_CHNL), .C_TAG_WIDTH (C_TAG_WIDTH), .C_VENDOR (C_VENDOR)) tx_mux_128_inst (/*AUTOINST*/ // Outputs .WR_DATA_REN (WR_DATA_REN[C_NUM_CHNL-1:0]), .WR_ACK (WR_ACK[C_NUM_CHNL-1:0]), .RD_ACK (RD_ACK[C_NUM_CHNL-1:0]), .INT_TAG (INT_TAG[5:0]), .INT_TAG_VALID (INT_TAG_VALID), .TX_ENG_RD_REQ_SENT (TX_ENG_RD_REQ_SENT), .TXR_DATA_VALID (TXR_DATA_VALID), .TXR_DATA (TXR_DATA[C_PCI_DATA_WIDTH-1:0]), .TXR_DATA_START_FLAG (TXR_DATA_START_FLAG), .TXR_DATA_START_OFFSET (TXR_DATA_START_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .TXR_DATA_END_FLAG (TXR_DATA_END_FLAG), .TXR_DATA_END_OFFSET (TXR_DATA_END_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .TXR_META_VALID (TXR_META_VALID), .TXR_META_FDWBE (TXR_META_FDWBE[`SIG_FBE_W-1:0]), .TXR_META_LDWBE (TXR_META_LDWBE[`SIG_LBE_W-1:0]), .TXR_META_ADDR (TXR_META_ADDR[`SIG_ADDR_W-1:0]), .TXR_META_LENGTH (TXR_META_LENGTH[`SIG_LEN_W-1:0]), .TXR_META_TAG (TXR_META_TAG[`SIG_TAG_W-1:0]), .TXR_META_TC (TXR_META_TC[`SIG_TC_W-1:0]), .TXR_META_ATTR (TXR_META_ATTR[`SIG_ATTR_W-1:0]), .TXR_META_TYPE (TXR_META_TYPE[`SIG_TYPE_W-1:0]), .TXR_META_EP (TXR_META_EP), // Inputs .CLK (CLK), .RST_IN (RST_IN), .WR_REQ (WR_REQ[C_NUM_CHNL-1:0]), .WR_ADDR (WR_ADDR[(C_NUM_CHNL*`SIG_ADDR_W)-1:0]), .WR_LEN (WR_LEN[(C_NUM_CHNL*`SIG_LEN_W)-1:0]), .WR_DATA (WR_DATA[(C_NUM_CHNL*C_PCI_DATA_WIDTH)-1:0]), .RD_REQ (RD_REQ[C_NUM_CHNL-1:0]), .RD_SG_CHNL (RD_SG_CHNL[(C_NUM_CHNL*2)-1:0]), .RD_ADDR (RD_ADDR[(C_NUM_CHNL*`SIG_ADDR_W)-1:0]), .RD_LEN (RD_LEN[(C_NUM_CHNL*`SIG_LEN_W)-1:0]), .EXT_TAG (EXT_TAG[C_TAG_WIDTH-1:0]), .EXT_TAG_VALID (EXT_TAG_VALID), .RXBUF_SPACE_AVAIL (RXBUF_SPACE_AVAIL), .TXR_DATA_READY (TXR_DATA_READY), .TXR_META_READY (TXR_META_READY)); end endgenerate endmodule // Local Variables: // verilog-library-directories:("." "registers/" "../common/") // End:
/* :Project FPGA-Imaging-Library :Design True2Comp :Function Convert true code to complemental code. :Module Main module :Version 1.0 :Modified 2015-05-01 Copyright (C) 2015 Dai Tianyu (dtysky) This library 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 library 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 library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Homepage for this project: http://ifl.dtysky.moe Sources for this project: https://github.com/dtysky/FPGA-Imaging-Library My e-mail: [email protected] My blog: http://dtysky.moe */ `timescale 1ns / 1ps module True2Comp( true, complement); parameter data_channel = 1; parameter data_width = 17; input[data_channel * data_width - 1 : 0] true; output[data_channel * data_width - 1 : 0] complement; genvar i; generate `define h (i + 1) * data_width - 1 `define l i * data_width for (i = 0; i < data_channel; i = i + 1) begin assign complement[`h : `l] = true[`h] == 0 ? true[`h : `l] : {1'b1, ~true[`h - 1 : `l] + 1}; end `undef h `undef l endgenerate endmodule
// (C) 1992-2014 Altera Corporation. All rights reserved. // 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. `timescale 1ns / 1ps module acl_ic_local_mem_router #( parameter integer DATA_W = 256, parameter integer BURSTCOUNT_W = 6, parameter integer ADDRESS_W = 32, parameter integer BYTEENA_W = DATA_W / 8, parameter integer NUM_BANKS = 8 ) ( input logic clock, input logic resetn, // Bank select (one-hot) input logic [NUM_BANKS-1:0] bank_select, // Master input logic m_arb_request, input logic m_arb_read, input logic m_arb_write, input logic [DATA_W-1:0] m_arb_writedata, input logic [BURSTCOUNT_W-1:0] m_arb_burstcount, input logic [ADDRESS_W-1:0] m_arb_address, input logic [BYTEENA_W-1:0] m_arb_byteenable, output logic m_arb_stall, output logic m_wrp_ack, output logic m_rrp_datavalid, output logic [DATA_W-1:0] m_rrp_data, // To each bank output logic b_arb_request [NUM_BANKS], output logic b_arb_read [NUM_BANKS], output logic b_arb_write [NUM_BANKS], output logic [DATA_W-1:0] b_arb_writedata [NUM_BANKS], output logic [BURSTCOUNT_W-1:0] b_arb_burstcount [NUM_BANKS], output logic [ADDRESS_W-$clog2(NUM_BANKS)-1:0] b_arb_address [NUM_BANKS], output logic [BYTEENA_W-1:0] b_arb_byteenable [NUM_BANKS], input logic b_arb_stall [NUM_BANKS], input logic b_wrp_ack [NUM_BANKS], input logic b_rrp_datavalid [NUM_BANKS], input logic [DATA_W-1:0] b_rrp_data [NUM_BANKS] ); integer i; always_comb begin m_arb_stall = 1'b0; m_wrp_ack = 1'b0; m_rrp_datavalid = 1'b0; m_rrp_data = '0; for( i = 0; i < NUM_BANKS; i = i + 1 ) begin:b b_arb_request[i] = m_arb_request & bank_select[i]; b_arb_read[i] = m_arb_read & bank_select[i]; b_arb_write[i] = m_arb_write & bank_select[i]; b_arb_writedata[i] = m_arb_writedata; b_arb_burstcount[i] = m_arb_burstcount; b_arb_address[i] = m_arb_address[ADDRESS_W-$clog2(NUM_BANKS)-1:0]; b_arb_byteenable[i] = m_arb_byteenable; m_arb_stall |= b_arb_stall[i] & bank_select[i]; m_wrp_ack |= b_wrp_ack[i]; m_rrp_datavalid |= b_rrp_datavalid[i]; m_rrp_data |= (b_rrp_datavalid[i] ? b_rrp_data[i] : '0); end end // Simulation-only assert - should eventually become hardware exception // Check that only one return path has active data. Colliding rrps // will lead to incorrect data, and may mean that there is a mismatch in // arbitration latency. // synthesis_off always @(posedge clock) begin logic [NUM_BANKS-1:0] b_rrp_datavalid_packed; for(int bitnum = 0; bitnum < NUM_BANKS; bitnum++ ) begin b_rrp_datavalid_packed[bitnum] = b_rrp_datavalid[bitnum]; end #1 assert ($onehot0(b_rrp_datavalid_packed)) else $fatal(0,"Local memory router: rrp collision. Data corrupted"); end // synthesis_on endmodule
/* Copyright (c) 2021 Alex Forencich Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ // Language: Verilog 2001 `resetall `timescale 1ns / 1ps `default_nettype none /* * Transceiver and PHY wrapper */ module eth_xcvr_phy_wrapper # ( parameter HAS_COMMON = 1, parameter DATA_WIDTH = 64, parameter CTRL_WIDTH = (DATA_WIDTH/8), parameter HDR_WIDTH = 2, parameter PRBS31_ENABLE = 0, parameter TX_SERDES_PIPELINE = 0, parameter RX_SERDES_PIPELINE = 0, parameter BITSLIP_HIGH_CYCLES = 1, parameter BITSLIP_LOW_CYCLES = 8, parameter COUNT_125US = 125000/6.4 ) ( input wire xcvr_ctrl_clk, input wire xcvr_ctrl_rst, /* * Common */ output wire xcvr_gtpowergood_out, /* * PLL out */ input wire xcvr_gtrefclk00_in, output wire xcvr_qpll0lock_out, output wire xcvr_qpll0outclk_out, output wire xcvr_qpll0outrefclk_out, /* * PLL in */ input wire xcvr_qpll0lock_in, output wire xcvr_qpll0reset_out, input wire xcvr_qpll0clk_in, input wire xcvr_qpll0refclk_in, /* * Serial data */ output wire xcvr_txp, output wire xcvr_txn, input wire xcvr_rxp, input wire xcvr_rxn, /* * PHY connections */ output wire phy_tx_clk, output wire phy_tx_rst, input wire [DATA_WIDTH-1:0] phy_xgmii_txd, input wire [CTRL_WIDTH-1:0] phy_xgmii_txc, output wire phy_rx_clk, output wire phy_rx_rst, output wire [DATA_WIDTH-1:0] phy_xgmii_rxd, output wire [CTRL_WIDTH-1:0] phy_xgmii_rxc, output wire phy_tx_bad_block, output wire [6:0] phy_rx_error_count, output wire phy_rx_bad_block, output wire phy_rx_sequence_error, output wire phy_rx_block_lock, output wire phy_rx_high_ber, input wire phy_tx_prbs31_enable, input wire phy_rx_prbs31_enable ); wire phy_rx_reset_req; wire gt_reset_tx_datapath = 1'b0; wire gt_reset_rx_datapath = phy_rx_reset_req; wire gt_reset_tx_done; wire gt_reset_rx_done; wire [5:0] gt_txheader; wire [63:0] gt_txdata; wire gt_rxgearboxslip; wire [5:0] gt_rxheader; wire [1:0] gt_rxheadervalid; wire [63:0] gt_rxdata; wire [1:0] gt_rxdatavalid; generate if (HAS_COMMON) begin : xcvr eth_xcvr_gt_full eth_xcvr_gt_full_inst ( // Common .gtwiz_reset_clk_freerun_in(xcvr_ctrl_clk), .gtwiz_reset_all_in(xcvr_ctrl_rst), .gtpowergood_out(xcvr_gtpowergood_out), // PLL .gtrefclk00_in(xcvr_gtrefclk00_in), .qpll0lock_out(xcvr_qpll0lock_out), .qpll0outclk_out(xcvr_qpll0outclk_out), .qpll0outrefclk_out(xcvr_qpll0outrefclk_out), // Serial data .gtytxp_out(xcvr_txp), .gtytxn_out(xcvr_txn), .gtyrxp_in(xcvr_rxp), .gtyrxn_in(xcvr_rxn), // Transmit .gtwiz_userclk_tx_reset_in(1'b0), .gtwiz_userclk_tx_srcclk_out(), .gtwiz_userclk_tx_usrclk_out(), .gtwiz_userclk_tx_usrclk2_out(phy_tx_clk), .gtwiz_userclk_tx_active_out(), .gtwiz_reset_tx_pll_and_datapath_in(1'b0), .gtwiz_reset_tx_datapath_in(gt_reset_tx_datapath), .gtwiz_reset_tx_done_out(gt_reset_tx_done), .txpmaresetdone_out(), .txprgdivresetdone_out(), .gtwiz_userdata_tx_in(gt_txdata), .txheader_in(gt_txheader), .txsequence_in(7'b0), // Receive .gtwiz_userclk_rx_reset_in(1'b0), .gtwiz_userclk_rx_srcclk_out(), .gtwiz_userclk_rx_usrclk_out(), .gtwiz_userclk_rx_usrclk2_out(phy_rx_clk), .gtwiz_userclk_rx_active_out(), .gtwiz_reset_rx_pll_and_datapath_in(1'b0), .gtwiz_reset_rx_datapath_in(gt_reset_rx_datapath), .gtwiz_reset_rx_cdr_stable_out(), .gtwiz_reset_rx_done_out(gt_reset_rx_done), .rxpmaresetdone_out(), .rxprgdivresetdone_out(), .rxgearboxslip_in(gt_rxgearboxslip), .gtwiz_userdata_rx_out(gt_rxdata), .rxdatavalid_out(gt_rxdatavalid), .rxheader_out(gt_rxheader), .rxheadervalid_out(gt_rxheadervalid), .rxstartofseq_out() ); end else begin : xcvr eth_xcvr_gt_channel eth_xcvr_gt_channel_inst ( // Common .gtwiz_reset_clk_freerun_in(xcvr_ctrl_clk), .gtwiz_reset_all_in(xcvr_ctrl_rst), .gtpowergood_out(xcvr_gtpowergood_out), // PLL .gtwiz_reset_qpll0lock_in(xcvr_qpll0lock_in), .gtwiz_reset_qpll0reset_out(xcvr_qpll0reset_out), .qpll0clk_in(xcvr_qpll0clk_in), .qpll0refclk_in(xcvr_qpll0refclk_in), .qpll1clk_in(1'b0), .qpll1refclk_in(1'b0), // Serial data .gtytxp_out(xcvr_txp), .gtytxn_out(xcvr_txn), .gtyrxp_in(xcvr_rxp), .gtyrxn_in(xcvr_rxn), // Transmit .gtwiz_userclk_tx_reset_in(1'b0), .gtwiz_userclk_tx_srcclk_out(), .gtwiz_userclk_tx_usrclk_out(), .gtwiz_userclk_tx_usrclk2_out(phy_tx_clk), .gtwiz_userclk_tx_active_out(), .gtwiz_reset_tx_pll_and_datapath_in(1'b0), .gtwiz_reset_tx_datapath_in(gt_reset_tx_datapath), .gtwiz_reset_tx_done_out(gt_reset_tx_done), .txpmaresetdone_out(), .txprgdivresetdone_out(), .gtwiz_userdata_tx_in(gt_txdata), .txheader_in(gt_txheader), .txsequence_in(7'b0), // Receive .gtwiz_userclk_rx_reset_in(1'b0), .gtwiz_userclk_rx_srcclk_out(), .gtwiz_userclk_rx_usrclk_out(), .gtwiz_userclk_rx_usrclk2_out(phy_rx_clk), .gtwiz_userclk_rx_active_out(), .gtwiz_reset_rx_pll_and_datapath_in(1'b0), .gtwiz_reset_rx_datapath_in(gt_reset_rx_datapath), .gtwiz_reset_rx_cdr_stable_out(), .gtwiz_reset_rx_done_out(gt_reset_rx_done), .rxpmaresetdone_out(), .rxprgdivresetdone_out(), .rxgearboxslip_in(gt_rxgearboxslip), .gtwiz_userdata_rx_out(gt_rxdata), .rxdatavalid_out(gt_rxdatavalid), .rxheader_out(gt_rxheader), .rxheadervalid_out(gt_rxheadervalid), .rxstartofseq_out() ); end endgenerate sync_reset #( .N(4) ) tx_reset_sync_inst ( .clk(phy_tx_clk), .rst(!gt_reset_tx_done), .out(phy_tx_rst) ); sync_reset #( .N(4) ) rx_reset_sync_inst ( .clk(phy_rx_clk), .rst(!gt_reset_rx_done), .out(phy_rx_rst) ); eth_phy_10g #( .DATA_WIDTH(DATA_WIDTH), .CTRL_WIDTH(CTRL_WIDTH), .HDR_WIDTH(HDR_WIDTH), .BIT_REVERSE(1), .SCRAMBLER_DISABLE(0), .PRBS31_ENABLE(PRBS31_ENABLE), .TX_SERDES_PIPELINE(TX_SERDES_PIPELINE), .RX_SERDES_PIPELINE(RX_SERDES_PIPELINE), .BITSLIP_HIGH_CYCLES(BITSLIP_HIGH_CYCLES), .BITSLIP_LOW_CYCLES(BITSLIP_LOW_CYCLES), .COUNT_125US(COUNT_125US) ) phy_inst ( .tx_clk(phy_tx_clk), .tx_rst(phy_tx_rst), .rx_clk(phy_rx_clk), .rx_rst(phy_rx_rst), .xgmii_txd(phy_xgmii_txd), .xgmii_txc(phy_xgmii_txc), .xgmii_rxd(phy_xgmii_rxd), .xgmii_rxc(phy_xgmii_rxc), .serdes_tx_data(gt_txdata), .serdes_tx_hdr(gt_txheader), .serdes_rx_data(gt_rxdata), .serdes_rx_hdr(gt_rxheader), .serdes_rx_bitslip(gt_rxgearboxslip), .serdes_rx_reset_req(phy_rx_reset_req), .tx_bad_block(phy_tx_bad_block), .rx_error_count(phy_rx_error_count), .rx_bad_block(phy_rx_bad_block), .rx_sequence_error(phy_rx_sequence_error), .rx_block_lock(phy_rx_block_lock), .rx_high_ber(phy_rx_high_ber), .tx_prbs31_enable(phy_tx_prbs31_enable), .rx_prbs31_enable(phy_rx_prbs31_enable) ); endmodule `resetall
/* Copyright (c) 2021 Alex Forencich Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ // Language: Verilog 2001 `resetall `timescale 1ns / 1ps `default_nettype none /* * Transceiver and PHY wrapper */ module eth_xcvr_phy_wrapper # ( parameter HAS_COMMON = 1, parameter DATA_WIDTH = 64, parameter CTRL_WIDTH = (DATA_WIDTH/8), parameter HDR_WIDTH = 2, parameter PRBS31_ENABLE = 0, parameter TX_SERDES_PIPELINE = 0, parameter RX_SERDES_PIPELINE = 0, parameter BITSLIP_HIGH_CYCLES = 1, parameter BITSLIP_LOW_CYCLES = 8, parameter COUNT_125US = 125000/6.4 ) ( input wire xcvr_ctrl_clk, input wire xcvr_ctrl_rst, /* * Common */ output wire xcvr_gtpowergood_out, /* * PLL out */ input wire xcvr_gtrefclk00_in, output wire xcvr_qpll0lock_out, output wire xcvr_qpll0outclk_out, output wire xcvr_qpll0outrefclk_out, /* * PLL in */ input wire xcvr_qpll0lock_in, output wire xcvr_qpll0reset_out, input wire xcvr_qpll0clk_in, input wire xcvr_qpll0refclk_in, /* * Serial data */ output wire xcvr_txp, output wire xcvr_txn, input wire xcvr_rxp, input wire xcvr_rxn, /* * PHY connections */ output wire phy_tx_clk, output wire phy_tx_rst, input wire [DATA_WIDTH-1:0] phy_xgmii_txd, input wire [CTRL_WIDTH-1:0] phy_xgmii_txc, output wire phy_rx_clk, output wire phy_rx_rst, output wire [DATA_WIDTH-1:0] phy_xgmii_rxd, output wire [CTRL_WIDTH-1:0] phy_xgmii_rxc, output wire phy_tx_bad_block, output wire [6:0] phy_rx_error_count, output wire phy_rx_bad_block, output wire phy_rx_sequence_error, output wire phy_rx_block_lock, output wire phy_rx_high_ber, input wire phy_tx_prbs31_enable, input wire phy_rx_prbs31_enable ); wire phy_rx_reset_req; wire gt_reset_tx_datapath = 1'b0; wire gt_reset_rx_datapath = phy_rx_reset_req; wire gt_reset_tx_done; wire gt_reset_rx_done; wire [5:0] gt_txheader; wire [63:0] gt_txdata; wire gt_rxgearboxslip; wire [5:0] gt_rxheader; wire [1:0] gt_rxheadervalid; wire [63:0] gt_rxdata; wire [1:0] gt_rxdatavalid; generate if (HAS_COMMON) begin : xcvr eth_xcvr_gt_full eth_xcvr_gt_full_inst ( // Common .gtwiz_reset_clk_freerun_in(xcvr_ctrl_clk), .gtwiz_reset_all_in(xcvr_ctrl_rst), .gtpowergood_out(xcvr_gtpowergood_out), // PLL .gtrefclk00_in(xcvr_gtrefclk00_in), .qpll0lock_out(xcvr_qpll0lock_out), .qpll0outclk_out(xcvr_qpll0outclk_out), .qpll0outrefclk_out(xcvr_qpll0outrefclk_out), // Serial data .gtytxp_out(xcvr_txp), .gtytxn_out(xcvr_txn), .gtyrxp_in(xcvr_rxp), .gtyrxn_in(xcvr_rxn), // Transmit .gtwiz_userclk_tx_reset_in(1'b0), .gtwiz_userclk_tx_srcclk_out(), .gtwiz_userclk_tx_usrclk_out(), .gtwiz_userclk_tx_usrclk2_out(phy_tx_clk), .gtwiz_userclk_tx_active_out(), .gtwiz_reset_tx_pll_and_datapath_in(1'b0), .gtwiz_reset_tx_datapath_in(gt_reset_tx_datapath), .gtwiz_reset_tx_done_out(gt_reset_tx_done), .txpmaresetdone_out(), .txprgdivresetdone_out(), .gtwiz_userdata_tx_in(gt_txdata), .txheader_in(gt_txheader), .txsequence_in(7'b0), // Receive .gtwiz_userclk_rx_reset_in(1'b0), .gtwiz_userclk_rx_srcclk_out(), .gtwiz_userclk_rx_usrclk_out(), .gtwiz_userclk_rx_usrclk2_out(phy_rx_clk), .gtwiz_userclk_rx_active_out(), .gtwiz_reset_rx_pll_and_datapath_in(1'b0), .gtwiz_reset_rx_datapath_in(gt_reset_rx_datapath), .gtwiz_reset_rx_cdr_stable_out(), .gtwiz_reset_rx_done_out(gt_reset_rx_done), .rxpmaresetdone_out(), .rxprgdivresetdone_out(), .rxgearboxslip_in(gt_rxgearboxslip), .gtwiz_userdata_rx_out(gt_rxdata), .rxdatavalid_out(gt_rxdatavalid), .rxheader_out(gt_rxheader), .rxheadervalid_out(gt_rxheadervalid), .rxstartofseq_out() ); end else begin : xcvr eth_xcvr_gt_channel eth_xcvr_gt_channel_inst ( // Common .gtwiz_reset_clk_freerun_in(xcvr_ctrl_clk), .gtwiz_reset_all_in(xcvr_ctrl_rst), .gtpowergood_out(xcvr_gtpowergood_out), // PLL .gtwiz_reset_qpll0lock_in(xcvr_qpll0lock_in), .gtwiz_reset_qpll0reset_out(xcvr_qpll0reset_out), .qpll0clk_in(xcvr_qpll0clk_in), .qpll0refclk_in(xcvr_qpll0refclk_in), .qpll1clk_in(1'b0), .qpll1refclk_in(1'b0), // Serial data .gtytxp_out(xcvr_txp), .gtytxn_out(xcvr_txn), .gtyrxp_in(xcvr_rxp), .gtyrxn_in(xcvr_rxn), // Transmit .gtwiz_userclk_tx_reset_in(1'b0), .gtwiz_userclk_tx_srcclk_out(), .gtwiz_userclk_tx_usrclk_out(), .gtwiz_userclk_tx_usrclk2_out(phy_tx_clk), .gtwiz_userclk_tx_active_out(), .gtwiz_reset_tx_pll_and_datapath_in(1'b0), .gtwiz_reset_tx_datapath_in(gt_reset_tx_datapath), .gtwiz_reset_tx_done_out(gt_reset_tx_done), .txpmaresetdone_out(), .txprgdivresetdone_out(), .gtwiz_userdata_tx_in(gt_txdata), .txheader_in(gt_txheader), .txsequence_in(7'b0), // Receive .gtwiz_userclk_rx_reset_in(1'b0), .gtwiz_userclk_rx_srcclk_out(), .gtwiz_userclk_rx_usrclk_out(), .gtwiz_userclk_rx_usrclk2_out(phy_rx_clk), .gtwiz_userclk_rx_active_out(), .gtwiz_reset_rx_pll_and_datapath_in(1'b0), .gtwiz_reset_rx_datapath_in(gt_reset_rx_datapath), .gtwiz_reset_rx_cdr_stable_out(), .gtwiz_reset_rx_done_out(gt_reset_rx_done), .rxpmaresetdone_out(), .rxprgdivresetdone_out(), .rxgearboxslip_in(gt_rxgearboxslip), .gtwiz_userdata_rx_out(gt_rxdata), .rxdatavalid_out(gt_rxdatavalid), .rxheader_out(gt_rxheader), .rxheadervalid_out(gt_rxheadervalid), .rxstartofseq_out() ); end endgenerate sync_reset #( .N(4) ) tx_reset_sync_inst ( .clk(phy_tx_clk), .rst(!gt_reset_tx_done), .out(phy_tx_rst) ); sync_reset #( .N(4) ) rx_reset_sync_inst ( .clk(phy_rx_clk), .rst(!gt_reset_rx_done), .out(phy_rx_rst) ); eth_phy_10g #( .DATA_WIDTH(DATA_WIDTH), .CTRL_WIDTH(CTRL_WIDTH), .HDR_WIDTH(HDR_WIDTH), .BIT_REVERSE(1), .SCRAMBLER_DISABLE(0), .PRBS31_ENABLE(PRBS31_ENABLE), .TX_SERDES_PIPELINE(TX_SERDES_PIPELINE), .RX_SERDES_PIPELINE(RX_SERDES_PIPELINE), .BITSLIP_HIGH_CYCLES(BITSLIP_HIGH_CYCLES), .BITSLIP_LOW_CYCLES(BITSLIP_LOW_CYCLES), .COUNT_125US(COUNT_125US) ) phy_inst ( .tx_clk(phy_tx_clk), .tx_rst(phy_tx_rst), .rx_clk(phy_rx_clk), .rx_rst(phy_rx_rst), .xgmii_txd(phy_xgmii_txd), .xgmii_txc(phy_xgmii_txc), .xgmii_rxd(phy_xgmii_rxd), .xgmii_rxc(phy_xgmii_rxc), .serdes_tx_data(gt_txdata), .serdes_tx_hdr(gt_txheader), .serdes_rx_data(gt_rxdata), .serdes_rx_hdr(gt_rxheader), .serdes_rx_bitslip(gt_rxgearboxslip), .serdes_rx_reset_req(phy_rx_reset_req), .tx_bad_block(phy_tx_bad_block), .rx_error_count(phy_rx_error_count), .rx_bad_block(phy_rx_bad_block), .rx_sequence_error(phy_rx_sequence_error), .rx_block_lock(phy_rx_block_lock), .rx_high_ber(phy_rx_high_ber), .tx_prbs31_enable(phy_tx_prbs31_enable), .rx_prbs31_enable(phy_rx_prbs31_enable) ); endmodule `resetall
/* Copyright (c) 2021 Alex Forencich Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ // Language: Verilog 2001 `resetall `timescale 1ns / 1ps `default_nettype none /* * Transceiver and PHY wrapper */ module eth_xcvr_phy_wrapper # ( parameter HAS_COMMON = 1, parameter DATA_WIDTH = 64, parameter CTRL_WIDTH = (DATA_WIDTH/8), parameter HDR_WIDTH = 2, parameter PRBS31_ENABLE = 0, parameter TX_SERDES_PIPELINE = 0, parameter RX_SERDES_PIPELINE = 0, parameter BITSLIP_HIGH_CYCLES = 1, parameter BITSLIP_LOW_CYCLES = 8, parameter COUNT_125US = 125000/6.4 ) ( input wire xcvr_ctrl_clk, input wire xcvr_ctrl_rst, /* * Common */ output wire xcvr_gtpowergood_out, /* * PLL out */ input wire xcvr_gtrefclk00_in, output wire xcvr_qpll0lock_out, output wire xcvr_qpll0outclk_out, output wire xcvr_qpll0outrefclk_out, /* * PLL in */ input wire xcvr_qpll0lock_in, output wire xcvr_qpll0reset_out, input wire xcvr_qpll0clk_in, input wire xcvr_qpll0refclk_in, /* * Serial data */ output wire xcvr_txp, output wire xcvr_txn, input wire xcvr_rxp, input wire xcvr_rxn, /* * PHY connections */ output wire phy_tx_clk, output wire phy_tx_rst, input wire [DATA_WIDTH-1:0] phy_xgmii_txd, input wire [CTRL_WIDTH-1:0] phy_xgmii_txc, output wire phy_rx_clk, output wire phy_rx_rst, output wire [DATA_WIDTH-1:0] phy_xgmii_rxd, output wire [CTRL_WIDTH-1:0] phy_xgmii_rxc, output wire phy_tx_bad_block, output wire [6:0] phy_rx_error_count, output wire phy_rx_bad_block, output wire phy_rx_sequence_error, output wire phy_rx_block_lock, output wire phy_rx_high_ber, input wire phy_tx_prbs31_enable, input wire phy_rx_prbs31_enable ); wire phy_rx_reset_req; wire gt_reset_tx_datapath = 1'b0; wire gt_reset_rx_datapath = phy_rx_reset_req; wire gt_reset_tx_done; wire gt_reset_rx_done; wire [5:0] gt_txheader; wire [63:0] gt_txdata; wire gt_rxgearboxslip; wire [5:0] gt_rxheader; wire [1:0] gt_rxheadervalid; wire [63:0] gt_rxdata; wire [1:0] gt_rxdatavalid; generate if (HAS_COMMON) begin : xcvr eth_xcvr_gt_full eth_xcvr_gt_full_inst ( // Common .gtwiz_reset_clk_freerun_in(xcvr_ctrl_clk), .gtwiz_reset_all_in(xcvr_ctrl_rst), .gtpowergood_out(xcvr_gtpowergood_out), // PLL .gtrefclk00_in(xcvr_gtrefclk00_in), .qpll0lock_out(xcvr_qpll0lock_out), .qpll0outclk_out(xcvr_qpll0outclk_out), .qpll0outrefclk_out(xcvr_qpll0outrefclk_out), // Serial data .gtytxp_out(xcvr_txp), .gtytxn_out(xcvr_txn), .gtyrxp_in(xcvr_rxp), .gtyrxn_in(xcvr_rxn), // Transmit .gtwiz_userclk_tx_reset_in(1'b0), .gtwiz_userclk_tx_srcclk_out(), .gtwiz_userclk_tx_usrclk_out(), .gtwiz_userclk_tx_usrclk2_out(phy_tx_clk), .gtwiz_userclk_tx_active_out(), .gtwiz_reset_tx_pll_and_datapath_in(1'b0), .gtwiz_reset_tx_datapath_in(gt_reset_tx_datapath), .gtwiz_reset_tx_done_out(gt_reset_tx_done), .txpmaresetdone_out(), .txprgdivresetdone_out(), .gtwiz_userdata_tx_in(gt_txdata), .txheader_in(gt_txheader), .txsequence_in(7'b0), // Receive .gtwiz_userclk_rx_reset_in(1'b0), .gtwiz_userclk_rx_srcclk_out(), .gtwiz_userclk_rx_usrclk_out(), .gtwiz_userclk_rx_usrclk2_out(phy_rx_clk), .gtwiz_userclk_rx_active_out(), .gtwiz_reset_rx_pll_and_datapath_in(1'b0), .gtwiz_reset_rx_datapath_in(gt_reset_rx_datapath), .gtwiz_reset_rx_cdr_stable_out(), .gtwiz_reset_rx_done_out(gt_reset_rx_done), .rxpmaresetdone_out(), .rxprgdivresetdone_out(), .rxgearboxslip_in(gt_rxgearboxslip), .gtwiz_userdata_rx_out(gt_rxdata), .rxdatavalid_out(gt_rxdatavalid), .rxheader_out(gt_rxheader), .rxheadervalid_out(gt_rxheadervalid), .rxstartofseq_out() ); end else begin : xcvr eth_xcvr_gt_channel eth_xcvr_gt_channel_inst ( // Common .gtwiz_reset_clk_freerun_in(xcvr_ctrl_clk), .gtwiz_reset_all_in(xcvr_ctrl_rst), .gtpowergood_out(xcvr_gtpowergood_out), // PLL .gtwiz_reset_qpll0lock_in(xcvr_qpll0lock_in), .gtwiz_reset_qpll0reset_out(xcvr_qpll0reset_out), .qpll0clk_in(xcvr_qpll0clk_in), .qpll0refclk_in(xcvr_qpll0refclk_in), .qpll1clk_in(1'b0), .qpll1refclk_in(1'b0), // Serial data .gtytxp_out(xcvr_txp), .gtytxn_out(xcvr_txn), .gtyrxp_in(xcvr_rxp), .gtyrxn_in(xcvr_rxn), // Transmit .gtwiz_userclk_tx_reset_in(1'b0), .gtwiz_userclk_tx_srcclk_out(), .gtwiz_userclk_tx_usrclk_out(), .gtwiz_userclk_tx_usrclk2_out(phy_tx_clk), .gtwiz_userclk_tx_active_out(), .gtwiz_reset_tx_pll_and_datapath_in(1'b0), .gtwiz_reset_tx_datapath_in(gt_reset_tx_datapath), .gtwiz_reset_tx_done_out(gt_reset_tx_done), .txpmaresetdone_out(), .txprgdivresetdone_out(), .gtwiz_userdata_tx_in(gt_txdata), .txheader_in(gt_txheader), .txsequence_in(7'b0), // Receive .gtwiz_userclk_rx_reset_in(1'b0), .gtwiz_userclk_rx_srcclk_out(), .gtwiz_userclk_rx_usrclk_out(), .gtwiz_userclk_rx_usrclk2_out(phy_rx_clk), .gtwiz_userclk_rx_active_out(), .gtwiz_reset_rx_pll_and_datapath_in(1'b0), .gtwiz_reset_rx_datapath_in(gt_reset_rx_datapath), .gtwiz_reset_rx_cdr_stable_out(), .gtwiz_reset_rx_done_out(gt_reset_rx_done), .rxpmaresetdone_out(), .rxprgdivresetdone_out(), .rxgearboxslip_in(gt_rxgearboxslip), .gtwiz_userdata_rx_out(gt_rxdata), .rxdatavalid_out(gt_rxdatavalid), .rxheader_out(gt_rxheader), .rxheadervalid_out(gt_rxheadervalid), .rxstartofseq_out() ); end endgenerate sync_reset #( .N(4) ) tx_reset_sync_inst ( .clk(phy_tx_clk), .rst(!gt_reset_tx_done), .out(phy_tx_rst) ); sync_reset #( .N(4) ) rx_reset_sync_inst ( .clk(phy_rx_clk), .rst(!gt_reset_rx_done), .out(phy_rx_rst) ); eth_phy_10g #( .DATA_WIDTH(DATA_WIDTH), .CTRL_WIDTH(CTRL_WIDTH), .HDR_WIDTH(HDR_WIDTH), .BIT_REVERSE(1), .SCRAMBLER_DISABLE(0), .PRBS31_ENABLE(PRBS31_ENABLE), .TX_SERDES_PIPELINE(TX_SERDES_PIPELINE), .RX_SERDES_PIPELINE(RX_SERDES_PIPELINE), .BITSLIP_HIGH_CYCLES(BITSLIP_HIGH_CYCLES), .BITSLIP_LOW_CYCLES(BITSLIP_LOW_CYCLES), .COUNT_125US(COUNT_125US) ) phy_inst ( .tx_clk(phy_tx_clk), .tx_rst(phy_tx_rst), .rx_clk(phy_rx_clk), .rx_rst(phy_rx_rst), .xgmii_txd(phy_xgmii_txd), .xgmii_txc(phy_xgmii_txc), .xgmii_rxd(phy_xgmii_rxd), .xgmii_rxc(phy_xgmii_rxc), .serdes_tx_data(gt_txdata), .serdes_tx_hdr(gt_txheader), .serdes_rx_data(gt_rxdata), .serdes_rx_hdr(gt_rxheader), .serdes_rx_bitslip(gt_rxgearboxslip), .serdes_rx_reset_req(phy_rx_reset_req), .tx_bad_block(phy_tx_bad_block), .rx_error_count(phy_rx_error_count), .rx_bad_block(phy_rx_bad_block), .rx_sequence_error(phy_rx_sequence_error), .rx_block_lock(phy_rx_block_lock), .rx_high_ber(phy_rx_high_ber), .tx_prbs31_enable(phy_tx_prbs31_enable), .rx_prbs31_enable(phy_rx_prbs31_enable) ); endmodule `resetall
/* Copyright (c) 2021 Alex Forencich Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ // Language: Verilog 2001 `resetall `timescale 1ns / 1ps `default_nettype none /* * Transceiver and PHY wrapper */ module eth_xcvr_phy_wrapper # ( parameter HAS_COMMON = 1, parameter DATA_WIDTH = 64, parameter CTRL_WIDTH = (DATA_WIDTH/8), parameter HDR_WIDTH = 2, parameter PRBS31_ENABLE = 0, parameter TX_SERDES_PIPELINE = 0, parameter RX_SERDES_PIPELINE = 0, parameter BITSLIP_HIGH_CYCLES = 1, parameter BITSLIP_LOW_CYCLES = 8, parameter COUNT_125US = 125000/6.4 ) ( input wire xcvr_ctrl_clk, input wire xcvr_ctrl_rst, /* * Common */ output wire xcvr_gtpowergood_out, /* * PLL out */ input wire xcvr_gtrefclk00_in, output wire xcvr_qpll0lock_out, output wire xcvr_qpll0outclk_out, output wire xcvr_qpll0outrefclk_out, /* * PLL in */ input wire xcvr_qpll0lock_in, output wire xcvr_qpll0reset_out, input wire xcvr_qpll0clk_in, input wire xcvr_qpll0refclk_in, /* * Serial data */ output wire xcvr_txp, output wire xcvr_txn, input wire xcvr_rxp, input wire xcvr_rxn, /* * PHY connections */ output wire phy_tx_clk, output wire phy_tx_rst, input wire [DATA_WIDTH-1:0] phy_xgmii_txd, input wire [CTRL_WIDTH-1:0] phy_xgmii_txc, output wire phy_rx_clk, output wire phy_rx_rst, output wire [DATA_WIDTH-1:0] phy_xgmii_rxd, output wire [CTRL_WIDTH-1:0] phy_xgmii_rxc, output wire phy_tx_bad_block, output wire [6:0] phy_rx_error_count, output wire phy_rx_bad_block, output wire phy_rx_sequence_error, output wire phy_rx_block_lock, output wire phy_rx_high_ber, input wire phy_tx_prbs31_enable, input wire phy_rx_prbs31_enable ); wire phy_rx_reset_req; wire gt_reset_tx_datapath = 1'b0; wire gt_reset_rx_datapath = phy_rx_reset_req; wire gt_reset_tx_done; wire gt_reset_rx_done; wire [5:0] gt_txheader; wire [63:0] gt_txdata; wire gt_rxgearboxslip; wire [5:0] gt_rxheader; wire [1:0] gt_rxheadervalid; wire [63:0] gt_rxdata; wire [1:0] gt_rxdatavalid; generate if (HAS_COMMON) begin : xcvr eth_xcvr_gt_full eth_xcvr_gt_full_inst ( // Common .gtwiz_reset_clk_freerun_in(xcvr_ctrl_clk), .gtwiz_reset_all_in(xcvr_ctrl_rst), .gtpowergood_out(xcvr_gtpowergood_out), // PLL .gtrefclk00_in(xcvr_gtrefclk00_in), .qpll0lock_out(xcvr_qpll0lock_out), .qpll0outclk_out(xcvr_qpll0outclk_out), .qpll0outrefclk_out(xcvr_qpll0outrefclk_out), // Serial data .gtytxp_out(xcvr_txp), .gtytxn_out(xcvr_txn), .gtyrxp_in(xcvr_rxp), .gtyrxn_in(xcvr_rxn), // Transmit .gtwiz_userclk_tx_reset_in(1'b0), .gtwiz_userclk_tx_srcclk_out(), .gtwiz_userclk_tx_usrclk_out(), .gtwiz_userclk_tx_usrclk2_out(phy_tx_clk), .gtwiz_userclk_tx_active_out(), .gtwiz_reset_tx_pll_and_datapath_in(1'b0), .gtwiz_reset_tx_datapath_in(gt_reset_tx_datapath), .gtwiz_reset_tx_done_out(gt_reset_tx_done), .txpmaresetdone_out(), .txprgdivresetdone_out(), .gtwiz_userdata_tx_in(gt_txdata), .txheader_in(gt_txheader), .txsequence_in(7'b0), // Receive .gtwiz_userclk_rx_reset_in(1'b0), .gtwiz_userclk_rx_srcclk_out(), .gtwiz_userclk_rx_usrclk_out(), .gtwiz_userclk_rx_usrclk2_out(phy_rx_clk), .gtwiz_userclk_rx_active_out(), .gtwiz_reset_rx_pll_and_datapath_in(1'b0), .gtwiz_reset_rx_datapath_in(gt_reset_rx_datapath), .gtwiz_reset_rx_cdr_stable_out(), .gtwiz_reset_rx_done_out(gt_reset_rx_done), .rxpmaresetdone_out(), .rxprgdivresetdone_out(), .rxgearboxslip_in(gt_rxgearboxslip), .gtwiz_userdata_rx_out(gt_rxdata), .rxdatavalid_out(gt_rxdatavalid), .rxheader_out(gt_rxheader), .rxheadervalid_out(gt_rxheadervalid), .rxstartofseq_out() ); end else begin : xcvr eth_xcvr_gt_channel eth_xcvr_gt_channel_inst ( // Common .gtwiz_reset_clk_freerun_in(xcvr_ctrl_clk), .gtwiz_reset_all_in(xcvr_ctrl_rst), .gtpowergood_out(xcvr_gtpowergood_out), // PLL .gtwiz_reset_qpll0lock_in(xcvr_qpll0lock_in), .gtwiz_reset_qpll0reset_out(xcvr_qpll0reset_out), .qpll0clk_in(xcvr_qpll0clk_in), .qpll0refclk_in(xcvr_qpll0refclk_in), .qpll1clk_in(1'b0), .qpll1refclk_in(1'b0), // Serial data .gtytxp_out(xcvr_txp), .gtytxn_out(xcvr_txn), .gtyrxp_in(xcvr_rxp), .gtyrxn_in(xcvr_rxn), // Transmit .gtwiz_userclk_tx_reset_in(1'b0), .gtwiz_userclk_tx_srcclk_out(), .gtwiz_userclk_tx_usrclk_out(), .gtwiz_userclk_tx_usrclk2_out(phy_tx_clk), .gtwiz_userclk_tx_active_out(), .gtwiz_reset_tx_pll_and_datapath_in(1'b0), .gtwiz_reset_tx_datapath_in(gt_reset_tx_datapath), .gtwiz_reset_tx_done_out(gt_reset_tx_done), .txpmaresetdone_out(), .txprgdivresetdone_out(), .gtwiz_userdata_tx_in(gt_txdata), .txheader_in(gt_txheader), .txsequence_in(7'b0), // Receive .gtwiz_userclk_rx_reset_in(1'b0), .gtwiz_userclk_rx_srcclk_out(), .gtwiz_userclk_rx_usrclk_out(), .gtwiz_userclk_rx_usrclk2_out(phy_rx_clk), .gtwiz_userclk_rx_active_out(), .gtwiz_reset_rx_pll_and_datapath_in(1'b0), .gtwiz_reset_rx_datapath_in(gt_reset_rx_datapath), .gtwiz_reset_rx_cdr_stable_out(), .gtwiz_reset_rx_done_out(gt_reset_rx_done), .rxpmaresetdone_out(), .rxprgdivresetdone_out(), .rxgearboxslip_in(gt_rxgearboxslip), .gtwiz_userdata_rx_out(gt_rxdata), .rxdatavalid_out(gt_rxdatavalid), .rxheader_out(gt_rxheader), .rxheadervalid_out(gt_rxheadervalid), .rxstartofseq_out() ); end endgenerate sync_reset #( .N(4) ) tx_reset_sync_inst ( .clk(phy_tx_clk), .rst(!gt_reset_tx_done), .out(phy_tx_rst) ); sync_reset #( .N(4) ) rx_reset_sync_inst ( .clk(phy_rx_clk), .rst(!gt_reset_rx_done), .out(phy_rx_rst) ); eth_phy_10g #( .DATA_WIDTH(DATA_WIDTH), .CTRL_WIDTH(CTRL_WIDTH), .HDR_WIDTH(HDR_WIDTH), .BIT_REVERSE(1), .SCRAMBLER_DISABLE(0), .PRBS31_ENABLE(PRBS31_ENABLE), .TX_SERDES_PIPELINE(TX_SERDES_PIPELINE), .RX_SERDES_PIPELINE(RX_SERDES_PIPELINE), .BITSLIP_HIGH_CYCLES(BITSLIP_HIGH_CYCLES), .BITSLIP_LOW_CYCLES(BITSLIP_LOW_CYCLES), .COUNT_125US(COUNT_125US) ) phy_inst ( .tx_clk(phy_tx_clk), .tx_rst(phy_tx_rst), .rx_clk(phy_rx_clk), .rx_rst(phy_rx_rst), .xgmii_txd(phy_xgmii_txd), .xgmii_txc(phy_xgmii_txc), .xgmii_rxd(phy_xgmii_rxd), .xgmii_rxc(phy_xgmii_rxc), .serdes_tx_data(gt_txdata), .serdes_tx_hdr(gt_txheader), .serdes_rx_data(gt_rxdata), .serdes_rx_hdr(gt_rxheader), .serdes_rx_bitslip(gt_rxgearboxslip), .serdes_rx_reset_req(phy_rx_reset_req), .tx_bad_block(phy_tx_bad_block), .rx_error_count(phy_rx_error_count), .rx_bad_block(phy_rx_bad_block), .rx_sequence_error(phy_rx_sequence_error), .rx_block_lock(phy_rx_block_lock), .rx_high_ber(phy_rx_high_ber), .tx_prbs31_enable(phy_tx_prbs31_enable), .rx_prbs31_enable(phy_rx_prbs31_enable) ); endmodule `resetall
/* Copyright (c) 2021 Alex Forencich Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ // Language: Verilog 2001 `resetall `timescale 1ns / 1ps `default_nettype none /* * Transceiver and PHY wrapper */ module eth_xcvr_phy_wrapper # ( parameter HAS_COMMON = 1, parameter DATA_WIDTH = 64, parameter CTRL_WIDTH = (DATA_WIDTH/8), parameter HDR_WIDTH = 2, parameter PRBS31_ENABLE = 0, parameter TX_SERDES_PIPELINE = 0, parameter RX_SERDES_PIPELINE = 0, parameter BITSLIP_HIGH_CYCLES = 1, parameter BITSLIP_LOW_CYCLES = 8, parameter COUNT_125US = 125000/6.4 ) ( input wire xcvr_ctrl_clk, input wire xcvr_ctrl_rst, /* * Common */ output wire xcvr_gtpowergood_out, /* * PLL out */ input wire xcvr_gtrefclk00_in, output wire xcvr_qpll0lock_out, output wire xcvr_qpll0outclk_out, output wire xcvr_qpll0outrefclk_out, /* * PLL in */ input wire xcvr_qpll0lock_in, output wire xcvr_qpll0reset_out, input wire xcvr_qpll0clk_in, input wire xcvr_qpll0refclk_in, /* * Serial data */ output wire xcvr_txp, output wire xcvr_txn, input wire xcvr_rxp, input wire xcvr_rxn, /* * PHY connections */ output wire phy_tx_clk, output wire phy_tx_rst, input wire [DATA_WIDTH-1:0] phy_xgmii_txd, input wire [CTRL_WIDTH-1:0] phy_xgmii_txc, output wire phy_rx_clk, output wire phy_rx_rst, output wire [DATA_WIDTH-1:0] phy_xgmii_rxd, output wire [CTRL_WIDTH-1:0] phy_xgmii_rxc, output wire phy_tx_bad_block, output wire [6:0] phy_rx_error_count, output wire phy_rx_bad_block, output wire phy_rx_sequence_error, output wire phy_rx_block_lock, output wire phy_rx_high_ber, input wire phy_tx_prbs31_enable, input wire phy_rx_prbs31_enable ); wire phy_rx_reset_req; wire gt_reset_tx_datapath = 1'b0; wire gt_reset_rx_datapath = phy_rx_reset_req; wire gt_reset_tx_done; wire gt_reset_rx_done; wire [5:0] gt_txheader; wire [63:0] gt_txdata; wire gt_rxgearboxslip; wire [5:0] gt_rxheader; wire [1:0] gt_rxheadervalid; wire [63:0] gt_rxdata; wire [1:0] gt_rxdatavalid; generate if (HAS_COMMON) begin : xcvr eth_xcvr_gt_full eth_xcvr_gt_full_inst ( // Common .gtwiz_reset_clk_freerun_in(xcvr_ctrl_clk), .gtwiz_reset_all_in(xcvr_ctrl_rst), .gtpowergood_out(xcvr_gtpowergood_out), // PLL .gtrefclk00_in(xcvr_gtrefclk00_in), .qpll0lock_out(xcvr_qpll0lock_out), .qpll0outclk_out(xcvr_qpll0outclk_out), .qpll0outrefclk_out(xcvr_qpll0outrefclk_out), // Serial data .gtytxp_out(xcvr_txp), .gtytxn_out(xcvr_txn), .gtyrxp_in(xcvr_rxp), .gtyrxn_in(xcvr_rxn), // Transmit .gtwiz_userclk_tx_reset_in(1'b0), .gtwiz_userclk_tx_srcclk_out(), .gtwiz_userclk_tx_usrclk_out(), .gtwiz_userclk_tx_usrclk2_out(phy_tx_clk), .gtwiz_userclk_tx_active_out(), .gtwiz_reset_tx_pll_and_datapath_in(1'b0), .gtwiz_reset_tx_datapath_in(gt_reset_tx_datapath), .gtwiz_reset_tx_done_out(gt_reset_tx_done), .txpmaresetdone_out(), .txprgdivresetdone_out(), .gtwiz_userdata_tx_in(gt_txdata), .txheader_in(gt_txheader), .txsequence_in(7'b0), // Receive .gtwiz_userclk_rx_reset_in(1'b0), .gtwiz_userclk_rx_srcclk_out(), .gtwiz_userclk_rx_usrclk_out(), .gtwiz_userclk_rx_usrclk2_out(phy_rx_clk), .gtwiz_userclk_rx_active_out(), .gtwiz_reset_rx_pll_and_datapath_in(1'b0), .gtwiz_reset_rx_datapath_in(gt_reset_rx_datapath), .gtwiz_reset_rx_cdr_stable_out(), .gtwiz_reset_rx_done_out(gt_reset_rx_done), .rxpmaresetdone_out(), .rxprgdivresetdone_out(), .rxgearboxslip_in(gt_rxgearboxslip), .gtwiz_userdata_rx_out(gt_rxdata), .rxdatavalid_out(gt_rxdatavalid), .rxheader_out(gt_rxheader), .rxheadervalid_out(gt_rxheadervalid), .rxstartofseq_out() ); end else begin : xcvr eth_xcvr_gt_channel eth_xcvr_gt_channel_inst ( // Common .gtwiz_reset_clk_freerun_in(xcvr_ctrl_clk), .gtwiz_reset_all_in(xcvr_ctrl_rst), .gtpowergood_out(xcvr_gtpowergood_out), // PLL .gtwiz_reset_qpll0lock_in(xcvr_qpll0lock_in), .gtwiz_reset_qpll0reset_out(xcvr_qpll0reset_out), .qpll0clk_in(xcvr_qpll0clk_in), .qpll0refclk_in(xcvr_qpll0refclk_in), .qpll1clk_in(1'b0), .qpll1refclk_in(1'b0), // Serial data .gtytxp_out(xcvr_txp), .gtytxn_out(xcvr_txn), .gtyrxp_in(xcvr_rxp), .gtyrxn_in(xcvr_rxn), // Transmit .gtwiz_userclk_tx_reset_in(1'b0), .gtwiz_userclk_tx_srcclk_out(), .gtwiz_userclk_tx_usrclk_out(), .gtwiz_userclk_tx_usrclk2_out(phy_tx_clk), .gtwiz_userclk_tx_active_out(), .gtwiz_reset_tx_pll_and_datapath_in(1'b0), .gtwiz_reset_tx_datapath_in(gt_reset_tx_datapath), .gtwiz_reset_tx_done_out(gt_reset_tx_done), .txpmaresetdone_out(), .txprgdivresetdone_out(), .gtwiz_userdata_tx_in(gt_txdata), .txheader_in(gt_txheader), .txsequence_in(7'b0), // Receive .gtwiz_userclk_rx_reset_in(1'b0), .gtwiz_userclk_rx_srcclk_out(), .gtwiz_userclk_rx_usrclk_out(), .gtwiz_userclk_rx_usrclk2_out(phy_rx_clk), .gtwiz_userclk_rx_active_out(), .gtwiz_reset_rx_pll_and_datapath_in(1'b0), .gtwiz_reset_rx_datapath_in(gt_reset_rx_datapath), .gtwiz_reset_rx_cdr_stable_out(), .gtwiz_reset_rx_done_out(gt_reset_rx_done), .rxpmaresetdone_out(), .rxprgdivresetdone_out(), .rxgearboxslip_in(gt_rxgearboxslip), .gtwiz_userdata_rx_out(gt_rxdata), .rxdatavalid_out(gt_rxdatavalid), .rxheader_out(gt_rxheader), .rxheadervalid_out(gt_rxheadervalid), .rxstartofseq_out() ); end endgenerate sync_reset #( .N(4) ) tx_reset_sync_inst ( .clk(phy_tx_clk), .rst(!gt_reset_tx_done), .out(phy_tx_rst) ); sync_reset #( .N(4) ) rx_reset_sync_inst ( .clk(phy_rx_clk), .rst(!gt_reset_rx_done), .out(phy_rx_rst) ); eth_phy_10g #( .DATA_WIDTH(DATA_WIDTH), .CTRL_WIDTH(CTRL_WIDTH), .HDR_WIDTH(HDR_WIDTH), .BIT_REVERSE(1), .SCRAMBLER_DISABLE(0), .PRBS31_ENABLE(PRBS31_ENABLE), .TX_SERDES_PIPELINE(TX_SERDES_PIPELINE), .RX_SERDES_PIPELINE(RX_SERDES_PIPELINE), .BITSLIP_HIGH_CYCLES(BITSLIP_HIGH_CYCLES), .BITSLIP_LOW_CYCLES(BITSLIP_LOW_CYCLES), .COUNT_125US(COUNT_125US) ) phy_inst ( .tx_clk(phy_tx_clk), .tx_rst(phy_tx_rst), .rx_clk(phy_rx_clk), .rx_rst(phy_rx_rst), .xgmii_txd(phy_xgmii_txd), .xgmii_txc(phy_xgmii_txc), .xgmii_rxd(phy_xgmii_rxd), .xgmii_rxc(phy_xgmii_rxc), .serdes_tx_data(gt_txdata), .serdes_tx_hdr(gt_txheader), .serdes_rx_data(gt_rxdata), .serdes_rx_hdr(gt_rxheader), .serdes_rx_bitslip(gt_rxgearboxslip), .serdes_rx_reset_req(phy_rx_reset_req), .tx_bad_block(phy_tx_bad_block), .rx_error_count(phy_rx_error_count), .rx_bad_block(phy_rx_bad_block), .rx_sequence_error(phy_rx_sequence_error), .rx_block_lock(phy_rx_block_lock), .rx_high_ber(phy_rx_high_ber), .tx_prbs31_enable(phy_tx_prbs31_enable), .rx_prbs31_enable(phy_rx_prbs31_enable) ); endmodule `resetall
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * 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. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // 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 REGENTS OF THE // UNIVERSITY OF CALIFORNIA 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. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: rx_engine_ultrascale.v // Version: 1.0 // Verilog Standard: Verilog-2001 // Description: The RX Engine (Ultrascale) takes a the two streams of // AXI from the Xilinx endpoint packets and provides the request packets on the // RXR Interface, and the completion packets on the RXC Interface. // This Engine is capable of operating at "line rate". // Author: Dustin Richmond (@darichmond) //----------------------------------------------------------------------------- `timescale 1ns/1ns `include "ultrascale.vh" `include "trellis.vh" module rx_engine_ultrascale #(parameter C_PCI_DATA_WIDTH = 128) (// Interface: Clocks input CLK, // Replacement for generic CLK // Interface: Resets input RST_BUS, // Replacement for generic RST_IN input RST_LOGIC, // Addition for RIFFA_RST output DONE_RXR_RST, output DONE_RXC_RST, // Interface: CQ input M_AXIS_CQ_TVALID, input M_AXIS_CQ_TLAST, input [C_PCI_DATA_WIDTH-1:0] M_AXIS_CQ_TDATA, input [(C_PCI_DATA_WIDTH/32)-1:0] M_AXIS_CQ_TKEEP, input [`SIG_CQ_TUSER_W-1:0] M_AXIS_CQ_TUSER, output M_AXIS_CQ_TREADY, // Interface: RC input M_AXIS_RC_TVALID, input M_AXIS_RC_TLAST, input [C_PCI_DATA_WIDTH-1:0] M_AXIS_RC_TDATA, input [(C_PCI_DATA_WIDTH/32)-1:0] M_AXIS_RC_TKEEP, input [`SIG_RC_TUSER_W-1:0] M_AXIS_RC_TUSER, output M_AXIS_RC_TREADY, // Interface: RXC Engine output [C_PCI_DATA_WIDTH-1:0] RXC_DATA, output RXC_DATA_VALID, output [(C_PCI_DATA_WIDTH/32)-1:0] RXC_DATA_WORD_ENABLE, output RXC_DATA_START_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] RXC_DATA_START_OFFSET, output RXC_DATA_END_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] RXC_DATA_END_OFFSET, output [`SIG_LBE_W-1:0] RXC_META_LDWBE, output [`SIG_FBE_W-1:0] RXC_META_FDWBE, output [`SIG_TAG_W-1:0] RXC_META_TAG, output [`SIG_LOWADDR_W-1:0] RXC_META_ADDR, output [`SIG_TYPE_W-1:0] RXC_META_TYPE, output [`SIG_LEN_W-1:0] RXC_META_LENGTH, output [`SIG_BYTECNT_W-1:0] RXC_META_BYTES_REMAINING, output [`SIG_CPLID_W-1:0] RXC_META_COMPLETER_ID, output RXC_META_EP, // Interface: RXR Engine output [C_PCI_DATA_WIDTH-1:0] RXR_DATA, output RXR_DATA_VALID, output [(C_PCI_DATA_WIDTH/32)-1:0] RXR_DATA_WORD_ENABLE, output RXR_DATA_START_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] RXR_DATA_START_OFFSET, output RXR_DATA_END_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] RXR_DATA_END_OFFSET, output [`SIG_FBE_W-1:0] RXR_META_FDWBE, output [`SIG_LBE_W-1:0] RXR_META_LDWBE, output [`SIG_TC_W-1:0] RXR_META_TC, output [`SIG_ATTR_W-1:0] RXR_META_ATTR, output [`SIG_TAG_W-1:0] RXR_META_TAG, output [`SIG_TYPE_W-1:0] RXR_META_TYPE, output [`SIG_ADDR_W-1:0] RXR_META_ADDR, output [`SIG_BARDECODE_W-1:0] RXR_META_BAR_DECODED, output [`SIG_REQID_W-1:0] RXR_META_REQUESTER_ID, output [`SIG_LEN_W-1:0] RXR_META_LENGTH, output RXR_META_EP ); localparam C_RX_PIPELINE_DEPTH = 3; rxc_engine_ultrascale #(///*AUTOINSTPARAM*/ // Parameters .C_PCI_DATA_WIDTH (C_PCI_DATA_WIDTH), .C_RX_PIPELINE_DEPTH (C_RX_PIPELINE_DEPTH)) rxc_engine_inst (/*AUTOINST*/ // Outputs .DONE_RXC_RST (DONE_RXC_RST), .M_AXIS_RC_TREADY (M_AXIS_RC_TREADY), .RXC_DATA (RXC_DATA[C_PCI_DATA_WIDTH-1:0]), .RXC_DATA_VALID (RXC_DATA_VALID), .RXC_DATA_WORD_ENABLE (RXC_DATA_WORD_ENABLE[(C_PCI_DATA_WIDTH/32)-1:0]), .RXC_DATA_START_FLAG (RXC_DATA_START_FLAG), .RXC_DATA_START_OFFSET (RXC_DATA_START_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .RXC_DATA_END_FLAG (RXC_DATA_END_FLAG), .RXC_DATA_END_OFFSET (RXC_DATA_END_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .RXC_META_LDWBE (RXC_META_LDWBE[`SIG_LBE_W-1:0]), .RXC_META_FDWBE (RXC_META_FDWBE[`SIG_FBE_W-1:0]), .RXC_META_TAG (RXC_META_TAG[`SIG_TAG_W-1:0]), .RXC_META_ADDR (RXC_META_ADDR[`SIG_LOWADDR_W-1:0]), .RXC_META_TYPE (RXC_META_TYPE[`SIG_TYPE_W-1:0]), .RXC_META_LENGTH (RXC_META_LENGTH[`SIG_LEN_W-1:0]), .RXC_META_BYTES_REMAINING (RXC_META_BYTES_REMAINING[`SIG_BYTECNT_W-1:0]), .RXC_META_COMPLETER_ID (RXC_META_COMPLETER_ID[`SIG_CPLID_W-1:0]), .RXC_META_EP (RXC_META_EP), // Inputs .CLK (CLK), .RST_BUS (RST_BUS), .RST_LOGIC (RST_LOGIC), .M_AXIS_RC_TVALID (M_AXIS_RC_TVALID), .M_AXIS_RC_TLAST (M_AXIS_RC_TLAST), .M_AXIS_RC_TDATA (M_AXIS_RC_TDATA[C_PCI_DATA_WIDTH-1:0]), .M_AXIS_RC_TKEEP (M_AXIS_RC_TKEEP[(C_PCI_DATA_WIDTH/32)-1:0]), .M_AXIS_RC_TUSER (M_AXIS_RC_TUSER[`SIG_RC_TUSER_W-1:0])); rxr_engine_ultrascale #(/*AUTOINSTPARAM*/ // Parameters .C_PCI_DATA_WIDTH (C_PCI_DATA_WIDTH), .C_RX_PIPELINE_DEPTH (C_RX_PIPELINE_DEPTH)) rxr_engine_inst (/*AUTOINST*/ // Outputs .DONE_RXR_RST (DONE_RXR_RST), .M_AXIS_CQ_TREADY (M_AXIS_CQ_TREADY), .RXR_DATA (RXR_DATA[C_PCI_DATA_WIDTH-1:0]), .RXR_DATA_VALID (RXR_DATA_VALID), .RXR_DATA_WORD_ENABLE (RXR_DATA_WORD_ENABLE[(C_PCI_DATA_WIDTH/32)-1:0]), .RXR_DATA_START_FLAG (RXR_DATA_START_FLAG), .RXR_DATA_START_OFFSET (RXR_DATA_START_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .RXR_DATA_END_FLAG (RXR_DATA_END_FLAG), .RXR_DATA_END_OFFSET (RXR_DATA_END_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .RXR_META_FDWBE (RXR_META_FDWBE[`SIG_FBE_W-1:0]), .RXR_META_LDWBE (RXR_META_LDWBE[`SIG_LBE_W-1:0]), .RXR_META_TC (RXR_META_TC[`SIG_TC_W-1:0]), .RXR_META_ATTR (RXR_META_ATTR[`SIG_ATTR_W-1:0]), .RXR_META_TAG (RXR_META_TAG[`SIG_TAG_W-1:0]), .RXR_META_TYPE (RXR_META_TYPE[`SIG_TYPE_W-1:0]), .RXR_META_ADDR (RXR_META_ADDR[`SIG_ADDR_W-1:0]), .RXR_META_BAR_DECODED (RXR_META_BAR_DECODED[`SIG_BARDECODE_W-1:0]), .RXR_META_REQUESTER_ID (RXR_META_REQUESTER_ID[`SIG_REQID_W-1:0]), .RXR_META_LENGTH (RXR_META_LENGTH[`SIG_LEN_W-1:0]), .RXR_META_EP (RXR_META_EP), // Inputs .CLK (CLK), .RST_BUS (RST_BUS), .RST_LOGIC (RST_LOGIC), .M_AXIS_CQ_TVALID (M_AXIS_CQ_TVALID), .M_AXIS_CQ_TLAST (M_AXIS_CQ_TLAST), .M_AXIS_CQ_TDATA (M_AXIS_CQ_TDATA[C_PCI_DATA_WIDTH-1:0]), .M_AXIS_CQ_TKEEP (M_AXIS_CQ_TKEEP[(C_PCI_DATA_WIDTH/32)-1:0]), .M_AXIS_CQ_TUSER (M_AXIS_CQ_TUSER[`SIG_CQ_TUSER_W-1:0])); endmodule // rx_engine_ultrascale // Local Variables: // verilog-library-directories:("." "./rx/") // End:
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * 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. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // 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 REGENTS OF THE // UNIVERSITY OF CALIFORNIA 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. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: rx_engine_ultrascale.v // Version: 1.0 // Verilog Standard: Verilog-2001 // Description: The RX Engine (Ultrascale) takes a the two streams of // AXI from the Xilinx endpoint packets and provides the request packets on the // RXR Interface, and the completion packets on the RXC Interface. // This Engine is capable of operating at "line rate". // Author: Dustin Richmond (@darichmond) //----------------------------------------------------------------------------- `timescale 1ns/1ns `include "ultrascale.vh" `include "trellis.vh" module rx_engine_ultrascale #(parameter C_PCI_DATA_WIDTH = 128) (// Interface: Clocks input CLK, // Replacement for generic CLK // Interface: Resets input RST_BUS, // Replacement for generic RST_IN input RST_LOGIC, // Addition for RIFFA_RST output DONE_RXR_RST, output DONE_RXC_RST, // Interface: CQ input M_AXIS_CQ_TVALID, input M_AXIS_CQ_TLAST, input [C_PCI_DATA_WIDTH-1:0] M_AXIS_CQ_TDATA, input [(C_PCI_DATA_WIDTH/32)-1:0] M_AXIS_CQ_TKEEP, input [`SIG_CQ_TUSER_W-1:0] M_AXIS_CQ_TUSER, output M_AXIS_CQ_TREADY, // Interface: RC input M_AXIS_RC_TVALID, input M_AXIS_RC_TLAST, input [C_PCI_DATA_WIDTH-1:0] M_AXIS_RC_TDATA, input [(C_PCI_DATA_WIDTH/32)-1:0] M_AXIS_RC_TKEEP, input [`SIG_RC_TUSER_W-1:0] M_AXIS_RC_TUSER, output M_AXIS_RC_TREADY, // Interface: RXC Engine output [C_PCI_DATA_WIDTH-1:0] RXC_DATA, output RXC_DATA_VALID, output [(C_PCI_DATA_WIDTH/32)-1:0] RXC_DATA_WORD_ENABLE, output RXC_DATA_START_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] RXC_DATA_START_OFFSET, output RXC_DATA_END_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] RXC_DATA_END_OFFSET, output [`SIG_LBE_W-1:0] RXC_META_LDWBE, output [`SIG_FBE_W-1:0] RXC_META_FDWBE, output [`SIG_TAG_W-1:0] RXC_META_TAG, output [`SIG_LOWADDR_W-1:0] RXC_META_ADDR, output [`SIG_TYPE_W-1:0] RXC_META_TYPE, output [`SIG_LEN_W-1:0] RXC_META_LENGTH, output [`SIG_BYTECNT_W-1:0] RXC_META_BYTES_REMAINING, output [`SIG_CPLID_W-1:0] RXC_META_COMPLETER_ID, output RXC_META_EP, // Interface: RXR Engine output [C_PCI_DATA_WIDTH-1:0] RXR_DATA, output RXR_DATA_VALID, output [(C_PCI_DATA_WIDTH/32)-1:0] RXR_DATA_WORD_ENABLE, output RXR_DATA_START_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] RXR_DATA_START_OFFSET, output RXR_DATA_END_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] RXR_DATA_END_OFFSET, output [`SIG_FBE_W-1:0] RXR_META_FDWBE, output [`SIG_LBE_W-1:0] RXR_META_LDWBE, output [`SIG_TC_W-1:0] RXR_META_TC, output [`SIG_ATTR_W-1:0] RXR_META_ATTR, output [`SIG_TAG_W-1:0] RXR_META_TAG, output [`SIG_TYPE_W-1:0] RXR_META_TYPE, output [`SIG_ADDR_W-1:0] RXR_META_ADDR, output [`SIG_BARDECODE_W-1:0] RXR_META_BAR_DECODED, output [`SIG_REQID_W-1:0] RXR_META_REQUESTER_ID, output [`SIG_LEN_W-1:0] RXR_META_LENGTH, output RXR_META_EP ); localparam C_RX_PIPELINE_DEPTH = 3; rxc_engine_ultrascale #(///*AUTOINSTPARAM*/ // Parameters .C_PCI_DATA_WIDTH (C_PCI_DATA_WIDTH), .C_RX_PIPELINE_DEPTH (C_RX_PIPELINE_DEPTH)) rxc_engine_inst (/*AUTOINST*/ // Outputs .DONE_RXC_RST (DONE_RXC_RST), .M_AXIS_RC_TREADY (M_AXIS_RC_TREADY), .RXC_DATA (RXC_DATA[C_PCI_DATA_WIDTH-1:0]), .RXC_DATA_VALID (RXC_DATA_VALID), .RXC_DATA_WORD_ENABLE (RXC_DATA_WORD_ENABLE[(C_PCI_DATA_WIDTH/32)-1:0]), .RXC_DATA_START_FLAG (RXC_DATA_START_FLAG), .RXC_DATA_START_OFFSET (RXC_DATA_START_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .RXC_DATA_END_FLAG (RXC_DATA_END_FLAG), .RXC_DATA_END_OFFSET (RXC_DATA_END_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .RXC_META_LDWBE (RXC_META_LDWBE[`SIG_LBE_W-1:0]), .RXC_META_FDWBE (RXC_META_FDWBE[`SIG_FBE_W-1:0]), .RXC_META_TAG (RXC_META_TAG[`SIG_TAG_W-1:0]), .RXC_META_ADDR (RXC_META_ADDR[`SIG_LOWADDR_W-1:0]), .RXC_META_TYPE (RXC_META_TYPE[`SIG_TYPE_W-1:0]), .RXC_META_LENGTH (RXC_META_LENGTH[`SIG_LEN_W-1:0]), .RXC_META_BYTES_REMAINING (RXC_META_BYTES_REMAINING[`SIG_BYTECNT_W-1:0]), .RXC_META_COMPLETER_ID (RXC_META_COMPLETER_ID[`SIG_CPLID_W-1:0]), .RXC_META_EP (RXC_META_EP), // Inputs .CLK (CLK), .RST_BUS (RST_BUS), .RST_LOGIC (RST_LOGIC), .M_AXIS_RC_TVALID (M_AXIS_RC_TVALID), .M_AXIS_RC_TLAST (M_AXIS_RC_TLAST), .M_AXIS_RC_TDATA (M_AXIS_RC_TDATA[C_PCI_DATA_WIDTH-1:0]), .M_AXIS_RC_TKEEP (M_AXIS_RC_TKEEP[(C_PCI_DATA_WIDTH/32)-1:0]), .M_AXIS_RC_TUSER (M_AXIS_RC_TUSER[`SIG_RC_TUSER_W-1:0])); rxr_engine_ultrascale #(/*AUTOINSTPARAM*/ // Parameters .C_PCI_DATA_WIDTH (C_PCI_DATA_WIDTH), .C_RX_PIPELINE_DEPTH (C_RX_PIPELINE_DEPTH)) rxr_engine_inst (/*AUTOINST*/ // Outputs .DONE_RXR_RST (DONE_RXR_RST), .M_AXIS_CQ_TREADY (M_AXIS_CQ_TREADY), .RXR_DATA (RXR_DATA[C_PCI_DATA_WIDTH-1:0]), .RXR_DATA_VALID (RXR_DATA_VALID), .RXR_DATA_WORD_ENABLE (RXR_DATA_WORD_ENABLE[(C_PCI_DATA_WIDTH/32)-1:0]), .RXR_DATA_START_FLAG (RXR_DATA_START_FLAG), .RXR_DATA_START_OFFSET (RXR_DATA_START_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .RXR_DATA_END_FLAG (RXR_DATA_END_FLAG), .RXR_DATA_END_OFFSET (RXR_DATA_END_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .RXR_META_FDWBE (RXR_META_FDWBE[`SIG_FBE_W-1:0]), .RXR_META_LDWBE (RXR_META_LDWBE[`SIG_LBE_W-1:0]), .RXR_META_TC (RXR_META_TC[`SIG_TC_W-1:0]), .RXR_META_ATTR (RXR_META_ATTR[`SIG_ATTR_W-1:0]), .RXR_META_TAG (RXR_META_TAG[`SIG_TAG_W-1:0]), .RXR_META_TYPE (RXR_META_TYPE[`SIG_TYPE_W-1:0]), .RXR_META_ADDR (RXR_META_ADDR[`SIG_ADDR_W-1:0]), .RXR_META_BAR_DECODED (RXR_META_BAR_DECODED[`SIG_BARDECODE_W-1:0]), .RXR_META_REQUESTER_ID (RXR_META_REQUESTER_ID[`SIG_REQID_W-1:0]), .RXR_META_LENGTH (RXR_META_LENGTH[`SIG_LEN_W-1:0]), .RXR_META_EP (RXR_META_EP), // Inputs .CLK (CLK), .RST_BUS (RST_BUS), .RST_LOGIC (RST_LOGIC), .M_AXIS_CQ_TVALID (M_AXIS_CQ_TVALID), .M_AXIS_CQ_TLAST (M_AXIS_CQ_TLAST), .M_AXIS_CQ_TDATA (M_AXIS_CQ_TDATA[C_PCI_DATA_WIDTH-1:0]), .M_AXIS_CQ_TKEEP (M_AXIS_CQ_TKEEP[(C_PCI_DATA_WIDTH/32)-1:0]), .M_AXIS_CQ_TUSER (M_AXIS_CQ_TUSER[`SIG_CQ_TUSER_W-1:0])); endmodule // rx_engine_ultrascale // Local Variables: // verilog-library-directories:("." "./rx/") // End:
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * 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. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // 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 REGENTS OF THE // UNIVERSITY OF CALIFORNIA 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. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: rx_engine_ultrascale.v // Version: 1.0 // Verilog Standard: Verilog-2001 // Description: The RX Engine (Ultrascale) takes a the two streams of // AXI from the Xilinx endpoint packets and provides the request packets on the // RXR Interface, and the completion packets on the RXC Interface. // This Engine is capable of operating at "line rate". // Author: Dustin Richmond (@darichmond) //----------------------------------------------------------------------------- `timescale 1ns/1ns `include "ultrascale.vh" `include "trellis.vh" module rx_engine_ultrascale #(parameter C_PCI_DATA_WIDTH = 128) (// Interface: Clocks input CLK, // Replacement for generic CLK // Interface: Resets input RST_BUS, // Replacement for generic RST_IN input RST_LOGIC, // Addition for RIFFA_RST output DONE_RXR_RST, output DONE_RXC_RST, // Interface: CQ input M_AXIS_CQ_TVALID, input M_AXIS_CQ_TLAST, input [C_PCI_DATA_WIDTH-1:0] M_AXIS_CQ_TDATA, input [(C_PCI_DATA_WIDTH/32)-1:0] M_AXIS_CQ_TKEEP, input [`SIG_CQ_TUSER_W-1:0] M_AXIS_CQ_TUSER, output M_AXIS_CQ_TREADY, // Interface: RC input M_AXIS_RC_TVALID, input M_AXIS_RC_TLAST, input [C_PCI_DATA_WIDTH-1:0] M_AXIS_RC_TDATA, input [(C_PCI_DATA_WIDTH/32)-1:0] M_AXIS_RC_TKEEP, input [`SIG_RC_TUSER_W-1:0] M_AXIS_RC_TUSER, output M_AXIS_RC_TREADY, // Interface: RXC Engine output [C_PCI_DATA_WIDTH-1:0] RXC_DATA, output RXC_DATA_VALID, output [(C_PCI_DATA_WIDTH/32)-1:0] RXC_DATA_WORD_ENABLE, output RXC_DATA_START_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] RXC_DATA_START_OFFSET, output RXC_DATA_END_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] RXC_DATA_END_OFFSET, output [`SIG_LBE_W-1:0] RXC_META_LDWBE, output [`SIG_FBE_W-1:0] RXC_META_FDWBE, output [`SIG_TAG_W-1:0] RXC_META_TAG, output [`SIG_LOWADDR_W-1:0] RXC_META_ADDR, output [`SIG_TYPE_W-1:0] RXC_META_TYPE, output [`SIG_LEN_W-1:0] RXC_META_LENGTH, output [`SIG_BYTECNT_W-1:0] RXC_META_BYTES_REMAINING, output [`SIG_CPLID_W-1:0] RXC_META_COMPLETER_ID, output RXC_META_EP, // Interface: RXR Engine output [C_PCI_DATA_WIDTH-1:0] RXR_DATA, output RXR_DATA_VALID, output [(C_PCI_DATA_WIDTH/32)-1:0] RXR_DATA_WORD_ENABLE, output RXR_DATA_START_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] RXR_DATA_START_OFFSET, output RXR_DATA_END_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] RXR_DATA_END_OFFSET, output [`SIG_FBE_W-1:0] RXR_META_FDWBE, output [`SIG_LBE_W-1:0] RXR_META_LDWBE, output [`SIG_TC_W-1:0] RXR_META_TC, output [`SIG_ATTR_W-1:0] RXR_META_ATTR, output [`SIG_TAG_W-1:0] RXR_META_TAG, output [`SIG_TYPE_W-1:0] RXR_META_TYPE, output [`SIG_ADDR_W-1:0] RXR_META_ADDR, output [`SIG_BARDECODE_W-1:0] RXR_META_BAR_DECODED, output [`SIG_REQID_W-1:0] RXR_META_REQUESTER_ID, output [`SIG_LEN_W-1:0] RXR_META_LENGTH, output RXR_META_EP ); localparam C_RX_PIPELINE_DEPTH = 3; rxc_engine_ultrascale #(///*AUTOINSTPARAM*/ // Parameters .C_PCI_DATA_WIDTH (C_PCI_DATA_WIDTH), .C_RX_PIPELINE_DEPTH (C_RX_PIPELINE_DEPTH)) rxc_engine_inst (/*AUTOINST*/ // Outputs .DONE_RXC_RST (DONE_RXC_RST), .M_AXIS_RC_TREADY (M_AXIS_RC_TREADY), .RXC_DATA (RXC_DATA[C_PCI_DATA_WIDTH-1:0]), .RXC_DATA_VALID (RXC_DATA_VALID), .RXC_DATA_WORD_ENABLE (RXC_DATA_WORD_ENABLE[(C_PCI_DATA_WIDTH/32)-1:0]), .RXC_DATA_START_FLAG (RXC_DATA_START_FLAG), .RXC_DATA_START_OFFSET (RXC_DATA_START_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .RXC_DATA_END_FLAG (RXC_DATA_END_FLAG), .RXC_DATA_END_OFFSET (RXC_DATA_END_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .RXC_META_LDWBE (RXC_META_LDWBE[`SIG_LBE_W-1:0]), .RXC_META_FDWBE (RXC_META_FDWBE[`SIG_FBE_W-1:0]), .RXC_META_TAG (RXC_META_TAG[`SIG_TAG_W-1:0]), .RXC_META_ADDR (RXC_META_ADDR[`SIG_LOWADDR_W-1:0]), .RXC_META_TYPE (RXC_META_TYPE[`SIG_TYPE_W-1:0]), .RXC_META_LENGTH (RXC_META_LENGTH[`SIG_LEN_W-1:0]), .RXC_META_BYTES_REMAINING (RXC_META_BYTES_REMAINING[`SIG_BYTECNT_W-1:0]), .RXC_META_COMPLETER_ID (RXC_META_COMPLETER_ID[`SIG_CPLID_W-1:0]), .RXC_META_EP (RXC_META_EP), // Inputs .CLK (CLK), .RST_BUS (RST_BUS), .RST_LOGIC (RST_LOGIC), .M_AXIS_RC_TVALID (M_AXIS_RC_TVALID), .M_AXIS_RC_TLAST (M_AXIS_RC_TLAST), .M_AXIS_RC_TDATA (M_AXIS_RC_TDATA[C_PCI_DATA_WIDTH-1:0]), .M_AXIS_RC_TKEEP (M_AXIS_RC_TKEEP[(C_PCI_DATA_WIDTH/32)-1:0]), .M_AXIS_RC_TUSER (M_AXIS_RC_TUSER[`SIG_RC_TUSER_W-1:0])); rxr_engine_ultrascale #(/*AUTOINSTPARAM*/ // Parameters .C_PCI_DATA_WIDTH (C_PCI_DATA_WIDTH), .C_RX_PIPELINE_DEPTH (C_RX_PIPELINE_DEPTH)) rxr_engine_inst (/*AUTOINST*/ // Outputs .DONE_RXR_RST (DONE_RXR_RST), .M_AXIS_CQ_TREADY (M_AXIS_CQ_TREADY), .RXR_DATA (RXR_DATA[C_PCI_DATA_WIDTH-1:0]), .RXR_DATA_VALID (RXR_DATA_VALID), .RXR_DATA_WORD_ENABLE (RXR_DATA_WORD_ENABLE[(C_PCI_DATA_WIDTH/32)-1:0]), .RXR_DATA_START_FLAG (RXR_DATA_START_FLAG), .RXR_DATA_START_OFFSET (RXR_DATA_START_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .RXR_DATA_END_FLAG (RXR_DATA_END_FLAG), .RXR_DATA_END_OFFSET (RXR_DATA_END_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .RXR_META_FDWBE (RXR_META_FDWBE[`SIG_FBE_W-1:0]), .RXR_META_LDWBE (RXR_META_LDWBE[`SIG_LBE_W-1:0]), .RXR_META_TC (RXR_META_TC[`SIG_TC_W-1:0]), .RXR_META_ATTR (RXR_META_ATTR[`SIG_ATTR_W-1:0]), .RXR_META_TAG (RXR_META_TAG[`SIG_TAG_W-1:0]), .RXR_META_TYPE (RXR_META_TYPE[`SIG_TYPE_W-1:0]), .RXR_META_ADDR (RXR_META_ADDR[`SIG_ADDR_W-1:0]), .RXR_META_BAR_DECODED (RXR_META_BAR_DECODED[`SIG_BARDECODE_W-1:0]), .RXR_META_REQUESTER_ID (RXR_META_REQUESTER_ID[`SIG_REQID_W-1:0]), .RXR_META_LENGTH (RXR_META_LENGTH[`SIG_LEN_W-1:0]), .RXR_META_EP (RXR_META_EP), // Inputs .CLK (CLK), .RST_BUS (RST_BUS), .RST_LOGIC (RST_LOGIC), .M_AXIS_CQ_TVALID (M_AXIS_CQ_TVALID), .M_AXIS_CQ_TLAST (M_AXIS_CQ_TLAST), .M_AXIS_CQ_TDATA (M_AXIS_CQ_TDATA[C_PCI_DATA_WIDTH-1:0]), .M_AXIS_CQ_TKEEP (M_AXIS_CQ_TKEEP[(C_PCI_DATA_WIDTH/32)-1:0]), .M_AXIS_CQ_TUSER (M_AXIS_CQ_TUSER[`SIG_CQ_TUSER_W-1:0])); endmodule // rx_engine_ultrascale // Local Variables: // verilog-library-directories:("." "./rx/") // End:
// DESCRIPTION: Verilator: Verilog Test module // // This file ONLY is placed into the Public Domain, for any use, // without warranty, 2013 by Sean Moore. module t (/*AUTOARG*/ // Inputs clk ); input clk; integer cyc=0; reg [63:0] crc; reg [63:0] sum; // Take CRC data and apply to testblock inputs wire [7:0] tripline = crc[7:0]; /*AUTOWIRE*/ wire valid; wire [3-1:0] value; PriorityChoice #(.OCODEWIDTH(3)) pe (.out(valid), .outN(value[2:0]), .tripline(tripline)); // Aggregate outputs into a single result vector wire [63:0] result = {59'h0, valid, value}; // Test loop always @ (posedge clk) begin `ifdef TEST_VERBOSE $write("[%0t] cyc==%0d crc=%x result=%x\n",$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 // Setup crc <= 64'h5aef0c8d_d70a4497; sum <= 64'h0; end else if (cyc<10) begin sum <= 64'h0; end else if (cyc<90) begin end else if (cyc==99) begin $write("[%0t] cyc==%0d crc=%x sum=%x\n",$time, cyc, crc, sum); if (crc !== 64'hc77bb9b3784ea091) $stop; // What checksum will we end up with (above print should match) `define EXPECTED_SUM 64'hc5fc632f816568fb if (sum !== `EXPECTED_SUM) $stop; $write("*-* All Finished *-*\n"); $finish; end end endmodule module PriorityChoice (out, outN, tripline); parameter OCODEWIDTH = 1; localparam CODEWIDTH=OCODEWIDTH-1; localparam SCODEWIDTH= (CODEWIDTH<1) ? 1 : CODEWIDTH; output reg out; output reg [OCODEWIDTH-1:0] outN; input wire [(1<<OCODEWIDTH)-1:0] tripline; wire left; wire [SCODEWIDTH-1:0] leftN; wire right; wire [SCODEWIDTH-1:0] rightN; generate if(OCODEWIDTH==1) begin assign left = tripline[1]; assign right = tripline[0]; always @(*) begin out <= left || right ; if(right) begin outN <= {1'b0}; end else begin outN <= {1'b1}; end end end else begin PriorityChoice #(.OCODEWIDTH(OCODEWIDTH-1)) leftMap ( .out(left), .outN(leftN), .tripline(tripline[(2<<CODEWIDTH)-1:(1<<CODEWIDTH)]) ); PriorityChoice #(.OCODEWIDTH(OCODEWIDTH-1)) rightMap ( .out(right), .outN(rightN), .tripline(tripline[(1<<CODEWIDTH)-1:0]) ); always @(*) begin if(right) begin out <= right; outN <= {1'b0, rightN[OCODEWIDTH-2:0]}; end else begin out <= left; outN <= {1'b1, leftN[OCODEWIDTH-2:0]}; end 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 Sean Moore. module t (/*AUTOARG*/ // Inputs clk ); input clk; integer cyc=0; reg [63:0] crc; reg [63:0] sum; // Take CRC data and apply to testblock inputs wire [7:0] tripline = crc[7:0]; /*AUTOWIRE*/ wire valid; wire [3-1:0] value; PriorityChoice #(.OCODEWIDTH(3)) pe (.out(valid), .outN(value[2:0]), .tripline(tripline)); // Aggregate outputs into a single result vector wire [63:0] result = {59'h0, valid, value}; // Test loop always @ (posedge clk) begin `ifdef TEST_VERBOSE $write("[%0t] cyc==%0d crc=%x result=%x\n",$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 // Setup crc <= 64'h5aef0c8d_d70a4497; sum <= 64'h0; end else if (cyc<10) begin sum <= 64'h0; end else if (cyc<90) begin end else if (cyc==99) begin $write("[%0t] cyc==%0d crc=%x sum=%x\n",$time, cyc, crc, sum); if (crc !== 64'hc77bb9b3784ea091) $stop; // What checksum will we end up with (above print should match) `define EXPECTED_SUM 64'hc5fc632f816568fb if (sum !== `EXPECTED_SUM) $stop; $write("*-* All Finished *-*\n"); $finish; end end endmodule module PriorityChoice (out, outN, tripline); parameter OCODEWIDTH = 1; localparam CODEWIDTH=OCODEWIDTH-1; localparam SCODEWIDTH= (CODEWIDTH<1) ? 1 : CODEWIDTH; output reg out; output reg [OCODEWIDTH-1:0] outN; input wire [(1<<OCODEWIDTH)-1:0] tripline; wire left; wire [SCODEWIDTH-1:0] leftN; wire right; wire [SCODEWIDTH-1:0] rightN; generate if(OCODEWIDTH==1) begin assign left = tripline[1]; assign right = tripline[0]; always @(*) begin out <= left || right ; if(right) begin outN <= {1'b0}; end else begin outN <= {1'b1}; end end end else begin PriorityChoice #(.OCODEWIDTH(OCODEWIDTH-1)) leftMap ( .out(left), .outN(leftN), .tripline(tripline[(2<<CODEWIDTH)-1:(1<<CODEWIDTH)]) ); PriorityChoice #(.OCODEWIDTH(OCODEWIDTH-1)) rightMap ( .out(right), .outN(rightN), .tripline(tripline[(1<<CODEWIDTH)-1:0]) ); always @(*) begin if(right) begin out <= right; outN <= {1'b0, rightN[OCODEWIDTH-2:0]}; end else begin out <= left; outN <= {1'b1, leftN[OCODEWIDTH-2:0]}; end end end endgenerate endmodule
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * 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. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // 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 REGENTS OF THE // UNIVERSITY OF CALIFORNIA 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. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: txc_engine_classic.v // Version: 1.0 // Verilog Standard: Verilog-2001 // Description: The TXC Engine takes unformatted completions, formats // these packets into "TLP's" or Transaction Layer Packets. These // packets must meet max-request, max-payload, and payload termination // requirements (see Read Completion Boundary). The TXC Engine does not // check these requirements during operation, but may do so during // simulation. // This file also contains the txc_formatter module, which formats // completion headers. // Author: Dustin Richmond (@darichmond) //----------------------------------------------------------------------------- `timescale 1ns/1ns `include "trellis.vh" // Defines the user-facing signal widths. `include "tlp.vh" // Defines the endpoint-facing field widths in a TLP module txc_engine_classic #(parameter C_PCI_DATA_WIDTH = 128, parameter C_PIPELINE_INPUT = 1, parameter C_PIPELINE_OUTPUT = 0, parameter C_MAX_PAYLOAD_DWORDS = 64, parameter C_DEPTH_PACKETS = 10, parameter C_VENDOR = "ALTERA") (// Interface: Clocks input CLK, // Interface: Resets input RST_IN, // Addition for RIFFA_RST output DONE_TXC_RST, // Interface: Configuration input [`SIG_CPLID_W-1:0] CONFIG_COMPLETER_ID, // Interface: TXC Classic input TXC_TLP_READY, output [C_PCI_DATA_WIDTH-1:0] TXC_TLP, output TXC_TLP_VALID, output TXC_TLP_START_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] TXC_TLP_START_OFFSET, output TXC_TLP_END_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] TXC_TLP_END_OFFSET, // Interface: TXC Engine input TXC_DATA_VALID, input [C_PCI_DATA_WIDTH-1:0] TXC_DATA, input TXC_DATA_START_FLAG, input [clog2s(C_PCI_DATA_WIDTH/32)-1:0] TXC_DATA_START_OFFSET, input TXC_DATA_END_FLAG, input [clog2s(C_PCI_DATA_WIDTH/32)-1:0] TXC_DATA_END_OFFSET, output TXC_DATA_READY, input TXC_META_VALID, input [`SIG_FBE_W-1:0] TXC_META_FDWBE, input [`SIG_LBE_W-1:0] TXC_META_LDWBE, input [`SIG_LOWADDR_W-1:0] TXC_META_ADDR, input [`SIG_TYPE_W-1:0] TXC_META_TYPE, input [`SIG_LEN_W-1:0] TXC_META_LENGTH, input [`SIG_BYTECNT_W-1:0] TXC_META_BYTE_COUNT, input [`SIG_TAG_W-1:0] TXC_META_TAG, input [`SIG_REQID_W-1:0] TXC_META_REQUESTER_ID, input [`SIG_TC_W-1:0] TXC_META_TC, input [`SIG_ATTR_W-1:0] TXC_META_ATTR, input TXC_META_EP, output TXC_META_READY); localparam C_DATA_WIDTH = C_PCI_DATA_WIDTH; localparam C_MAX_HDR_WIDTH = `TLP_MAXHDR_W; localparam C_MAX_ALIGN_WIDTH = (C_VENDOR == "ALTERA") ? 32: (C_VENDOR == "XILINX") ? 0 : 0; localparam C_PIPELINE_FORMATTER_INPUT = C_PIPELINE_INPUT; localparam C_PIPELINE_FORMATTER_OUTPUT = C_PIPELINE_OUTPUT; localparam C_FORMATTER_DELAY = C_PIPELINE_FORMATTER_OUTPUT + C_PIPELINE_FORMATTER_INPUT; /*AUTOWIRE*/ /*AUTOINPUT*/ ///*AUTOOUTPUT*/ wire wTxHdrReady; wire wTxHdrValid; wire [C_MAX_HDR_WIDTH-1:0] wTxHdr; wire [`SIG_TYPE_W-1:0] wTxType; wire [`SIG_NONPAY_W-1:0] wTxHdrNonpayLen; wire [`SIG_PACKETLEN_W-1:0] wTxHdrPacketLen; wire [`SIG_LEN_W-1:0] wTxHdrPayloadLen; wire wTxHdrNopayload; assign DONE_TXC_RST = ~RST_IN; txc_formatter_classic #( .C_PIPELINE_OUTPUT (C_PIPELINE_FORMATTER_OUTPUT), .C_PIPELINE_INPUT (C_PIPELINE_FORMATTER_INPUT), /*AUTOINSTPARAM*/ // Parameters .C_PCI_DATA_WIDTH (C_PCI_DATA_WIDTH), .C_MAX_HDR_WIDTH (C_MAX_HDR_WIDTH), .C_MAX_ALIGN_WIDTH (C_MAX_ALIGN_WIDTH), .C_VENDOR (C_VENDOR)) txc_formatter_inst ( // Outputs .TX_HDR_VALID (wTxHdrValid), .TX_HDR (wTxHdr[C_MAX_HDR_WIDTH-1:0]), .TX_HDR_NOPAYLOAD (wTxHdrNopayload), .TX_HDR_PAYLOAD_LEN (wTxHdrPayloadLen[`SIG_LEN_W-1:0]), .TX_HDR_NONPAY_LEN (wTxHdrNonpayLen[`SIG_NONPAY_W-1:0]), .TX_HDR_PACKET_LEN (wTxHdrPacketLen[`SIG_PACKETLEN_W-1:0]), // Inputs .TX_HDR_READY (wTxHdrReady), /*AUTOINST*/ // Outputs .TXC_META_READY (TXC_META_READY), // Inputs .CLK (CLK), .RST_IN (RST_IN), .CONFIG_COMPLETER_ID (CONFIG_COMPLETER_ID[`SIG_CPLID_W-1:0]), .TXC_META_VALID (TXC_META_VALID), .TXC_META_FDWBE (TXC_META_FDWBE[`SIG_FBE_W-1:0]), .TXC_META_LDWBE (TXC_META_LDWBE[`SIG_LBE_W-1:0]), .TXC_META_ADDR (TXC_META_ADDR[`SIG_LOWADDR_W-1:0]), .TXC_META_LENGTH (TXC_META_LENGTH[`SIG_LEN_W-1:0]), .TXC_META_BYTE_COUNT (TXC_META_BYTE_COUNT[`SIG_BYTECNT_W-1:0]), .TXC_META_TAG (TXC_META_TAG[`SIG_TAG_W-1:0]), .TXC_META_TYPE (TXC_META_TYPE[`SIG_TYPE_W-1:0]), .TXC_META_REQUESTER_ID (TXC_META_REQUESTER_ID[`SIG_REQID_W-1:0]), .TXC_META_TC (TXC_META_TC[`SIG_TC_W-1:0]), .TXC_META_ATTR (TXC_META_ATTR[`SIG_ATTR_W-1:0]), .TXC_META_EP (TXC_META_EP)); tx_engine #( .C_DATA_WIDTH (C_PCI_DATA_WIDTH), /*AUTOINSTPARAM*/ // Parameters .C_DEPTH_PACKETS (C_DEPTH_PACKETS), .C_PIPELINE_INPUT (C_PIPELINE_INPUT), .C_PIPELINE_OUTPUT (C_PIPELINE_OUTPUT), .C_FORMATTER_DELAY (C_FORMATTER_DELAY), .C_MAX_HDR_WIDTH (C_MAX_HDR_WIDTH), .C_MAX_PAYLOAD_DWORDS (C_MAX_PAYLOAD_DWORDS), .C_VENDOR (C_VENDOR)) txc_engine_inst ( // Outputs .TX_HDR_READY (wTxHdrReady), .TX_DATA_READY (TXC_DATA_READY), .TX_PKT (TXC_TLP[C_DATA_WIDTH-1:0]), .TX_PKT_START_FLAG (TXC_TLP_START_FLAG), .TX_PKT_START_OFFSET (TXC_TLP_START_OFFSET[clog2s(C_DATA_WIDTH/32)-1:0]), .TX_PKT_END_FLAG (TXC_TLP_END_FLAG), .TX_PKT_END_OFFSET (TXC_TLP_END_OFFSET[clog2s(C_DATA_WIDTH/32)-1:0]), .TX_PKT_VALID (TXC_TLP_VALID), // Inputs .TX_HDR_VALID (wTxHdrValid), .TX_HDR (wTxHdr[C_MAX_HDR_WIDTH-1:0]), .TX_HDR_NOPAYLOAD (wTxHdrNopayload), .TX_HDR_PAYLOAD_LEN (wTxHdrPayloadLen[`SIG_LEN_W-1:0]), .TX_HDR_NONPAY_LEN (wTxHdrNonpayLen[`SIG_NONPAY_W-1:0]), .TX_HDR_PACKET_LEN (wTxHdrPacketLen[`SIG_PACKETLEN_W-1:0]), .TX_DATA_VALID (TXC_DATA_VALID), .TX_DATA (TXC_DATA[C_DATA_WIDTH-1:0]), .TX_DATA_START_FLAG (TXC_DATA_START_FLAG), .TX_DATA_START_OFFSET (TXC_DATA_START_OFFSET[clog2s(C_DATA_WIDTH/32)-1:0]), .TX_DATA_END_FLAG (TXC_DATA_END_FLAG), .TX_DATA_END_OFFSET (TXC_DATA_END_OFFSET[clog2s(C_DATA_WIDTH/32)-1:0]), .TX_PKT_READY (TXC_TLP_READY), /*AUTOINST*/ // Inputs .CLK (CLK), .RST_IN (RST_IN)); endmodule module txc_formatter_classic #( parameter C_PCI_DATA_WIDTH = 10'd128, parameter C_MAX_HDR_WIDTH = `TLP_MAXHDR_W, parameter C_MAX_ALIGN_WIDTH = 32, parameter C_PIPELINE_INPUT = 1, parameter C_PIPELINE_OUTPUT = 1, parameter C_VENDOR = "ALTERA" ) ( // Interface: Clocks input CLK, // Interface: Resets input RST_IN, // Interface: Configuration input [`SIG_CPLID_W-1:0] CONFIG_COMPLETER_ID, // Interface: TXC input TXC_META_VALID, input [`SIG_FBE_W-1:0] TXC_META_FDWBE, input [`SIG_LBE_W-1:0] TXC_META_LDWBE, input [`SIG_LOWADDR_W-1:0] TXC_META_ADDR, input [`SIG_LEN_W-1:0] TXC_META_LENGTH, input [`SIG_BYTECNT_W-1:0] TXC_META_BYTE_COUNT, input [`SIG_TAG_W-1:0] TXC_META_TAG, input [`SIG_TYPE_W-1:0] TXC_META_TYPE, input [`SIG_REQID_W-1:0] TXC_META_REQUESTER_ID, input [`SIG_TC_W-1:0] TXC_META_TC, input [`SIG_ATTR_W-1:0] TXC_META_ATTR, input TXC_META_EP, output TXC_META_READY, // Interface: TX HDR output TX_HDR_VALID, output [C_MAX_HDR_WIDTH-1:0] TX_HDR, output [`SIG_LEN_W-1:0] TX_HDR_PAYLOAD_LEN, output [`SIG_NONPAY_W-1:0] TX_HDR_NONPAY_LEN, output [`SIG_PACKETLEN_W-1:0] TX_HDR_PACKET_LEN, output TX_HDR_NOPAYLOAD, input TX_HDR_READY ); wire [C_MAX_HDR_WIDTH-1:0] wCplHdr; wire wTxHdrReady; wire wTxHdrValid; wire [C_MAX_HDR_WIDTH-1:0] wTxHdr; wire [`SIG_TYPE_W-1:0] wTxType; wire [`SIG_NONPAY_W-1:0] wTxHdrNonpayLen; wire [`SIG_PACKETLEN_W-1:0] wTxHdrPacketLen; wire [`SIG_LEN_W-1:0] wTxHdrPayloadLen; wire wTxHdrNopayload; wire [`TLP_CPLADDR_W-1:0] wTxLoAddr; // Reserved Fields assign wCplHdr[`TLP_RSVD0_R] = `TLP_RSVD0_V; assign wCplHdr[`TLP_ADDRTYPE_R] = `TLP_ADDRTYPE_W'b0; assign wCplHdr[`TLP_TH_R] = `TLP_TH_W'b0; assign wCplHdr[`TLP_RSVD1_R] = `TLP_RSVD1_V; assign wCplHdr[`TLP_RSVD2_R] = `TLP_RSVD2_V; assign wCplHdr[`TLP_CPLBCM_R] = `TLP_CPLBCM_W'b0; assign wCplHdr[`TLP_CPLRSVD0_R] = `TLP_CPLRSVD0_W'b0; assign wCplHdr[127:96] = 32'b0; // Generic Header Fields assign wCplHdr[`TLP_LEN_R] = TXC_META_LENGTH; assign wCplHdr[`TLP_EP_R] = TXC_META_EP; assign wCplHdr[`TLP_TD_R] = `TLP_NODIGEST_V; assign wCplHdr[`TLP_ATTR0_R] = TXC_META_ATTR[1:0]; assign wCplHdr[`TLP_ATTR1_R] = TXC_META_ATTR[2]; assign {wCplHdr[`TLP_FMT_R], wCplHdr[`TLP_TYPE_R]} = trellis_to_tlp_type(TXC_META_TYPE,0); assign wCplHdr[`TLP_TC_R] = TXC_META_TC; // Completion Specific Fields assign wCplHdr[`TLP_CPLBYTECNT_R] = TXC_META_BYTE_COUNT; assign wCplHdr[`TLP_CPLSTAT_R] = 0; assign wCplHdr[`TLP_CPLCPLID_R] = CONFIG_COMPLETER_ID; assign wCplHdr[`TLP_CPLADDR_R] = TXC_META_ADDR; assign wCplHdr[`TLP_CPLTAG_R] = TXC_META_TAG; assign wCplHdr[`TLP_CPLREQID_R] = TXC_META_REQUESTER_ID; // Metadata, to the aligner assign wTxLoAddr = wTxHdr[`TLP_CPLADDR_R]; assign wTxHdrNopayload = ~wTxHdr[`TLP_PAYBIT_I]; assign wTxHdrNonpayLen = 3 + ((C_VENDOR == "ALTERA")? {3'b0,(~wTxLoAddr[2] & ~wTxHdrNopayload)} : 4'b0); assign wTxHdrPayloadLen = wTxHdrNopayload ? 0 : wTxHdr[`TLP_LEN_R]; assign wTxHdrPacketLen = wTxHdrPayloadLen + wTxHdrNonpayLen; pipeline #(// Parameters .C_DEPTH (C_PIPELINE_INPUT?1:0), .C_WIDTH (C_MAX_HDR_WIDTH), .C_USE_MEMORY (0) /*AUTOINSTPARAM*/) input_inst (// Outputs .WR_DATA_READY (TXC_META_READY), .RD_DATA (wTxHdr), .RD_DATA_VALID (wTxHdrValid), // Inputs .WR_DATA (wCplHdr), .WR_DATA_VALID (TXC_META_VALID), .RD_DATA_READY (wTxHdrReady), /*AUTOINST*/ // Inputs .CLK (CLK), .RST_IN (RST_IN)); pipeline #( // Parameters .C_DEPTH (C_PIPELINE_OUTPUT?1:0), .C_WIDTH (C_MAX_HDR_WIDTH+ 1 + `SIG_PACKETLEN_W + `SIG_LEN_W + `SIG_NONPAY_W), .C_USE_MEMORY (0) /*AUTOINSTPARAM*/) output_inst ( // Outputs .WR_DATA_READY (wTxHdrReady), .RD_DATA ({TX_HDR,TX_HDR_NOPAYLOAD,TX_HDR_PACKET_LEN,TX_HDR_PAYLOAD_LEN,TX_HDR_NONPAY_LEN}), .RD_DATA_VALID (TX_HDR_VALID), // Inputs .WR_DATA ({wTxHdr,wTxHdrNopayload,wTxHdrPacketLen,wTxHdrPayloadLen,wTxHdrNonpayLen}), .WR_DATA_VALID (wTxHdrValid), .RD_DATA_READY (TX_HDR_READY), /*AUTOINST*/ // Inputs .CLK (CLK), .RST_IN (RST_IN)); endmodule // Local Variables: // verilog-library-directories:("." "../../../common/" "../../common/") // End:
(* -*- coding: utf-8 -*- *) (************************************************************************) (* v * The Coq Proof Assistant / The Coq Development Team *) (* <O___,, * INRIA - CNRS - LIX - LRI - PPS - Copyright 1999-2015 *) (* \VV/ **************************************************************) (* // * This file is distributed under the terms of the *) (* * GNU Lesser General Public License Version 2.1 *) (************************************************************************) (** * Euclidean Division *) (** Initial Contribution by Claude Marché and Xavier Urbain *) Require Export ZArith_base. Require Import Zbool Omega ZArithRing Zcomplements Setoid Morphisms. Local Open Scope Z_scope. (** The definition of the division is now in [BinIntDef], the initial specifications and properties are in [BinInt]. *) Notation Zdiv_eucl_POS := Z.pos_div_eucl (compat "8.3"). Notation Zdiv_eucl := Z.div_eucl (compat "8.3"). Notation Zdiv := Z.div (compat "8.3"). Notation Zmod := Z.modulo (compat "8.3"). Notation Zdiv_eucl_eq := Z.div_eucl_eq (compat "8.3"). Notation Z_div_mod_eq_full := Z.div_mod (compat "8.3"). Notation Zmod_POS_bound := Z.pos_div_eucl_bound (compat "8.3"). Notation Zmod_pos_bound := Z.mod_pos_bound (compat "8.3"). Notation Zmod_neg_bound := Z.mod_neg_bound (compat "8.3"). (** * Main division theorems *) (** NB: many things are stated twice for compatibility reasons *) Lemma Z_div_mod_POS : forall b:Z, b > 0 -> forall a:positive, let (q, r) := Z.pos_div_eucl a b in Zpos a = b * q + r /\ 0 <= r < b. Proof. intros b Hb a. Z.swap_greater. generalize (Z.pos_div_eucl_eq a b Hb) (Z.pos_div_eucl_bound a b Hb). destruct Z.pos_div_eucl. rewrite Z.mul_comm. auto. Qed. Theorem Z_div_mod a b : b > 0 -> let (q, r) := Z.div_eucl a b in a = b * q + r /\ 0 <= r < b. Proof. Z.swap_greater. intros Hb. assert (Hb' : b<>0) by (now destruct b). generalize (Z.div_eucl_eq a b Hb') (Z.mod_pos_bound a b Hb). unfold Z.modulo. destruct Z.div_eucl. auto. Qed. (** For stating the fully general result, let's give a short name to the condition on the remainder. *) Definition Remainder r b := 0 <= r < b \/ b < r <= 0. (** Another equivalent formulation: *) Definition Remainder_alt r b := Z.abs r < Z.abs b /\ Z.sgn r <> - Z.sgn b. (* In the last formulation, [ Z.sgn r <> - Z.sgn b ] is less nice than saying [ Z.sgn r = Z.sgn b ], but at least it works even when [r] is null. *) Lemma Remainder_equiv : forall r b, Remainder r b <-> Remainder_alt r b. Proof. intros; unfold Remainder, Remainder_alt; omega with *. Qed. Hint Unfold Remainder. (** Now comes the fully general result about Euclidean division. *) Theorem Z_div_mod_full a b : b <> 0 -> let (q, r) := Z.div_eucl a b in a = b * q + r /\ Remainder r b. Proof. intros Hb. generalize (Z.div_eucl_eq a b Hb) (Z.mod_pos_bound a b) (Z.mod_neg_bound a b). unfold Z.modulo. destruct Z.div_eucl as (q,r). intros EQ POS NEG. split; auto. red; destruct b. now destruct Hb. left; now apply POS. right; now apply NEG. Qed. (** The same results as before, stated separately in terms of Z.div and Z.modulo *) Lemma Z_mod_remainder a b : b<>0 -> Remainder (a mod b) b. Proof. unfold Z.modulo; intros Hb; generalize (Z_div_mod_full a b Hb); auto. destruct Z.div_eucl; tauto. Qed. Lemma Z_mod_lt a b : b > 0 -> 0 <= a mod b < b. Proof (fun Hb => Z.mod_pos_bound a b (Z.gt_lt _ _ Hb)). Lemma Z_mod_neg a b : b < 0 -> b < a mod b <= 0. Proof (Z.mod_neg_bound a b). Lemma Z_div_mod_eq a b : b > 0 -> a = b*(a/b) + (a mod b). Proof. intros Hb; apply Z.div_mod; auto with zarith. Qed. Lemma Zmod_eq_full a b : b<>0 -> a mod b = a - (a/b)*b. Proof. intros. rewrite Z.mul_comm. now apply Z.mod_eq. Qed. Lemma Zmod_eq a b : b>0 -> a mod b = a - (a/b)*b. Proof. intros. apply Zmod_eq_full. now destruct b. Qed. (** Existence theorem *) Theorem Zdiv_eucl_exist : forall (b:Z)(Hb:b>0)(a:Z), {qr : Z * Z | let (q, r) := qr in a = b * q + r /\ 0 <= r < b}. Proof. intros b Hb a. exists (Z.div_eucl a b). exact (Z_div_mod a b Hb). Qed. Arguments Zdiv_eucl_exist : default implicits. (** Uniqueness theorems *) Theorem Zdiv_mod_unique b q1 q2 r1 r2 : 0 <= r1 < Z.abs b -> 0 <= r2 < Z.abs b -> b*q1+r1 = b*q2+r2 -> q1=q2 /\ r1=r2. Proof. intros Hr1 Hr2 H. rewrite <- (Z.abs_sgn b), <- !Z.mul_assoc in H. destruct (Z.div_mod_unique (Z.abs b) (Z.sgn b * q1) (Z.sgn b * q2) r1 r2); auto. split; trivial. apply Z.mul_cancel_l with (Z.sgn b); trivial. rewrite Z.sgn_null_iff, <- Z.abs_0_iff. destruct Hr1; Z.order. Qed. Theorem Zdiv_mod_unique_2 : forall b q1 q2 r1 r2:Z, Remainder r1 b -> Remainder r2 b -> b*q1+r1 = b*q2+r2 -> q1=q2 /\ r1=r2. Proof Z.div_mod_unique. Theorem Zdiv_unique_full: forall a b q r, Remainder r b -> a = b*q + r -> q = a/b. Proof Z.div_unique. Theorem Zdiv_unique: forall a b q r, 0 <= r < b -> a = b*q + r -> q = a/b. Proof. intros; eapply Zdiv_unique_full; eauto. Qed. Theorem Zmod_unique_full: forall a b q r, Remainder r b -> a = b*q + r -> r = a mod b. Proof Z.mod_unique. Theorem Zmod_unique: forall a b q r, 0 <= r < b -> a = b*q + r -> r = a mod b. Proof. intros; eapply Zmod_unique_full; eauto. Qed. (** * Basic values of divisions and modulo. *) Lemma Zmod_0_l: forall a, 0 mod a = 0. Proof. destruct a; simpl; auto. Qed. Lemma Zmod_0_r: forall a, a mod 0 = 0. Proof. destruct a; simpl; auto. Qed. Lemma Zdiv_0_l: forall a, 0/a = 0. Proof. destruct a; simpl; auto. Qed. Lemma Zdiv_0_r: forall a, a/0 = 0. Proof. destruct a; simpl; auto. Qed. Ltac zero_or_not a := destruct (Z.eq_dec a 0); [subst; rewrite ?Zmod_0_l, ?Zdiv_0_l, ?Zmod_0_r, ?Zdiv_0_r; auto with zarith|]. Lemma Zmod_1_r: forall a, a mod 1 = 0. Proof. intros. zero_or_not a. apply Z.mod_1_r. Qed. Lemma Zdiv_1_r: forall a, a/1 = a. Proof. intros. zero_or_not a. apply Z.div_1_r. Qed. Hint Resolve Zmod_0_l Zmod_0_r Zdiv_0_l Zdiv_0_r Zdiv_1_r Zmod_1_r : zarith. Lemma Zdiv_1_l: forall a, 1 < a -> 1/a = 0. Proof Z.div_1_l. Lemma Zmod_1_l: forall a, 1 < a -> 1 mod a = 1. Proof Z.mod_1_l. Lemma Z_div_same_full : forall a:Z, a<>0 -> a/a = 1. Proof Z.div_same. Lemma Z_mod_same_full : forall a, a mod a = 0. Proof. intros. zero_or_not a. apply Z.mod_same; auto. Qed. Lemma Z_mod_mult : forall a b, (a*b) mod b = 0. Proof. intros. zero_or_not b. apply Z.mod_mul. auto. Qed. Lemma Z_div_mult_full : forall a b:Z, b <> 0 -> (a*b)/b = a. Proof Z.div_mul. (** * Order results about Z.modulo and Z.div *) (* Division of positive numbers is positive. *) Lemma Z_div_pos: forall a b, b > 0 -> 0 <= a -> 0 <= a/b. Proof. intros. apply Z.div_pos; auto with zarith. Qed. Lemma Z_div_ge0: forall a b, b > 0 -> a >= 0 -> a/b >=0. Proof. intros; generalize (Z_div_pos a b H); auto with zarith. Qed. (** As soon as the divisor is greater or equal than 2, the division is strictly decreasing. *) Lemma Z_div_lt : forall a b:Z, b >= 2 -> a > 0 -> a/b < a. Proof. intros. apply Z.div_lt; auto with zarith. Qed. (** A division of a small number by a bigger one yields zero. *) Theorem Zdiv_small: forall a b, 0 <= a < b -> a/b = 0. Proof Z.div_small. (** Same situation, in term of modulo: *) Theorem Zmod_small: forall a n, 0 <= a < n -> a mod n = a. Proof Z.mod_small. (** [Z.ge] is compatible with a positive division. *) Lemma Z_div_ge : forall a b c:Z, c > 0 -> a >= b -> a/c >= b/c. Proof. intros. apply Z.le_ge. apply Z.div_le_mono; auto with zarith. Qed. (** Same, with [Z.le]. *) Lemma Z_div_le : forall a b c:Z, c > 0 -> a <= b -> a/c <= b/c. Proof. intros. apply Z.div_le_mono; auto with zarith. Qed. (** With our choice of division, rounding of (a/b) is always done toward bottom: *) Lemma Z_mult_div_ge : forall a b:Z, b > 0 -> b*(a/b) <= a. Proof. intros. apply Z.mul_div_le; auto with zarith. Qed. Lemma Z_mult_div_ge_neg : forall a b:Z, b < 0 -> b*(a/b) >= a. Proof. intros. apply Z.le_ge. apply Z.mul_div_ge; auto with zarith. Qed. (** The previous inequalities are exact iff the modulo is zero. *) Lemma Z_div_exact_full_1 : forall a b:Z, a = b*(a/b) -> a mod b = 0. Proof. intros a b. zero_or_not b. rewrite Z.div_exact; auto. Qed. Lemma Z_div_exact_full_2 : forall a b:Z, b <> 0 -> a mod b = 0 -> a = b*(a/b). Proof. intros; rewrite Z.div_exact; auto. Qed. (** A modulo cannot grow beyond its starting point. *) Theorem Zmod_le: forall a b, 0 < b -> 0 <= a -> a mod b <= a. Proof. intros. apply Z.mod_le; auto. Qed. (** Some additionnal inequalities about Z.div. *) Theorem Zdiv_lt_upper_bound: forall a b q, 0 < b -> a < q*b -> a/b < q. Proof. intros a b q; rewrite Z.mul_comm; apply Z.div_lt_upper_bound. Qed. Theorem Zdiv_le_upper_bound: forall a b q, 0 < b -> a <= q*b -> a/b <= q. Proof. intros a b q; rewrite Z.mul_comm; apply Z.div_le_upper_bound. Qed. Theorem Zdiv_le_lower_bound: forall a b q, 0 < b -> q*b <= a -> q <= a/b. Proof. intros a b q; rewrite Z.mul_comm; apply Z.div_le_lower_bound. Qed. (** A division of respect opposite monotonicity for the divisor *) Lemma Zdiv_le_compat_l: forall p q r, 0 <= p -> 0 < q < r -> p / r <= p / q. Proof. intros; apply Z.div_le_compat_l; auto with zarith. Qed. Theorem Zdiv_sgn: forall a b, 0 <= Z.sgn (a/b) * Z.sgn a * Z.sgn b. Proof. destruct a as [ |a|a]; destruct b as [ |b|b]; simpl; auto with zarith; generalize (Z.div_pos (Zpos a) (Zpos b)); unfold Z.div, Z.div_eucl; destruct Z.pos_div_eucl as (q,r); destruct r; omega with *. Qed. (** * Relations between usual operations and Z.modulo and Z.div *) Lemma Z_mod_plus_full : forall a b c:Z, (a + b * c) mod c = a mod c. Proof. intros. zero_or_not c. apply Z.mod_add; auto. Qed. Lemma Z_div_plus_full : forall a b c:Z, c <> 0 -> (a + b * c) / c = a / c + b. Proof Z.div_add. Theorem Z_div_plus_full_l: forall a b c : Z, b <> 0 -> (a * b + c) / b = a + c / b. Proof Z.div_add_l. (** [Z.opp] and [Z.div], [Z.modulo]. Due to the choice of convention for our Euclidean division, some of the relations about [Z.opp] and divisions are rather complex. *) Lemma Zdiv_opp_opp : forall a b:Z, (-a)/(-b) = a/b. Proof. intros. zero_or_not b. apply Z.div_opp_opp; auto. Qed. Lemma Zmod_opp_opp : forall a b:Z, (-a) mod (-b) = - (a mod b). Proof. intros. zero_or_not b. apply Z.mod_opp_opp; auto. Qed. Lemma Z_mod_zero_opp_full : forall a b:Z, a mod b = 0 -> (-a) mod b = 0. Proof. intros. zero_or_not b. apply Z.mod_opp_l_z; auto. Qed. Lemma Z_mod_nz_opp_full : forall a b:Z, a mod b <> 0 -> (-a) mod b = b - (a mod b). Proof. intros. zero_or_not b. apply Z.mod_opp_l_nz; auto. Qed. Lemma Z_mod_zero_opp_r : forall a b:Z, a mod b = 0 -> a mod (-b) = 0. Proof. intros. zero_or_not b. apply Z.mod_opp_r_z; auto. Qed. Lemma Z_mod_nz_opp_r : forall a b:Z, a mod b <> 0 -> a mod (-b) = (a mod b) - b. Proof. intros. zero_or_not b. apply Z.mod_opp_r_nz; auto. Qed. Lemma Z_div_zero_opp_full : forall a b:Z, a mod b = 0 -> (-a)/b = -(a/b). Proof. intros. zero_or_not b. apply Z.div_opp_l_z; auto. Qed. Lemma Z_div_nz_opp_full : forall a b:Z, a mod b <> 0 -> (-a)/b = -(a/b)-1. Proof. intros a b. zero_or_not b. intros; rewrite Z.div_opp_l_nz; auto. Qed. Lemma Z_div_zero_opp_r : forall a b:Z, a mod b = 0 -> a/(-b) = -(a/b). Proof. intros. zero_or_not b. apply Z.div_opp_r_z; auto. Qed. Lemma Z_div_nz_opp_r : forall a b:Z, a mod b <> 0 -> a/(-b) = -(a/b)-1. Proof. intros a b. zero_or_not b. intros; rewrite Z.div_opp_r_nz; auto. Qed. (** Cancellations. *) Lemma Zdiv_mult_cancel_r : forall a b c:Z, c <> 0 -> (a*c)/(b*c) = a/b. Proof. intros. zero_or_not b. apply Z.div_mul_cancel_r; auto. Qed. Lemma Zdiv_mult_cancel_l : forall a b c:Z, c<>0 -> (c*a)/(c*b) = a/b. Proof. intros. rewrite (Z.mul_comm c b); zero_or_not b. rewrite (Z.mul_comm b c). apply Z.div_mul_cancel_l; auto. Qed. Lemma Zmult_mod_distr_l: forall a b c, (c*a) mod (c*b) = c * (a mod b). Proof. intros. zero_or_not c. rewrite (Z.mul_comm c b); zero_or_not b. rewrite (Z.mul_comm b c). apply Z.mul_mod_distr_l; auto. Qed. Lemma Zmult_mod_distr_r: forall a b c, (a*c) mod (b*c) = (a mod b) * c. Proof. intros. zero_or_not b. rewrite (Z.mul_comm b c); zero_or_not c. rewrite (Z.mul_comm c b). apply Z.mul_mod_distr_r; auto. Qed. (** Operations modulo. *) Theorem Zmod_mod: forall a n, (a mod n) mod n = a mod n. Proof. intros. zero_or_not n. apply Z.mod_mod; auto. Qed. Theorem Zmult_mod: forall a b n, (a * b) mod n = ((a mod n) * (b mod n)) mod n. Proof. intros. zero_or_not n. apply Z.mul_mod; auto. Qed. Theorem Zplus_mod: forall a b n, (a + b) mod n = (a mod n + b mod n) mod n. Proof. intros. zero_or_not n. apply Z.add_mod; auto. Qed. Theorem Zminus_mod: forall a b n, (a - b) mod n = (a mod n - b mod n) mod n. Proof. intros. replace (a - b) with (a + (-1) * b); auto with zarith. replace (a mod n - b mod n) with (a mod n + (-1) * (b mod n)); auto with zarith. rewrite Zplus_mod. rewrite Zmult_mod. rewrite Zplus_mod with (b:=(-1) * (b mod n)). rewrite Zmult_mod. rewrite Zmult_mod with (b:= b mod n). repeat rewrite Zmod_mod; auto. Qed. Lemma Zplus_mod_idemp_l: forall a b n, (a mod n + b) mod n = (a + b) mod n. Proof. intros; rewrite Zplus_mod, Zmod_mod, <- Zplus_mod; auto. Qed. Lemma Zplus_mod_idemp_r: forall a b n, (b + a mod n) mod n = (b + a) mod n. Proof. intros; rewrite Zplus_mod, Zmod_mod, <- Zplus_mod; auto. Qed. Lemma Zminus_mod_idemp_l: forall a b n, (a mod n - b) mod n = (a - b) mod n. Proof. intros; rewrite Zminus_mod, Zmod_mod, <- Zminus_mod; auto. Qed. Lemma Zminus_mod_idemp_r: forall a b n, (a - b mod n) mod n = (a - b) mod n. Proof. intros; rewrite Zminus_mod, Zmod_mod, <- Zminus_mod; auto. Qed. Lemma Zmult_mod_idemp_l: forall a b n, (a mod n * b) mod n = (a * b) mod n. Proof. intros; rewrite Zmult_mod, Zmod_mod, <- Zmult_mod; auto. Qed. Lemma Zmult_mod_idemp_r: forall a b n, (b * (a mod n)) mod n = (b * a) mod n. Proof. intros; rewrite Zmult_mod, Zmod_mod, <- Zmult_mod; auto. Qed. (** For a specific number N, equality modulo N is hence a nice setoid equivalence, compatible with [+], [-] and [*]. *) Section EqualityModulo. Variable N:Z. Definition eqm a b := (a mod N = b mod N). Infix "==" := eqm (at level 70). Lemma eqm_refl : forall a, a == a. Proof. unfold eqm; auto. Qed. Lemma eqm_sym : forall a b, a == b -> b == a. Proof. unfold eqm; auto. Qed. Lemma eqm_trans : forall a b c, a == b -> b == c -> a == c. Proof. unfold eqm; eauto with *. Qed. Instance eqm_setoid : Equivalence eqm. Proof. constructor; [exact eqm_refl | exact eqm_sym | exact eqm_trans]. Qed. Instance Zplus_eqm : Proper (eqm ==> eqm ==> eqm) Z.add. Proof. unfold eqm; repeat red; intros. rewrite Zplus_mod, H, H0, <- Zplus_mod; auto. Qed. Instance Zminus_eqm : Proper (eqm ==> eqm ==> eqm) Z.sub. Proof. unfold eqm; repeat red; intros. rewrite Zminus_mod, H, H0, <- Zminus_mod; auto. Qed. Instance Zmult_eqm : Proper (eqm ==> eqm ==> eqm) Z.mul. Proof. unfold eqm; repeat red; intros. rewrite Zmult_mod, H, H0, <- Zmult_mod; auto. Qed. Instance Zopp_eqm : Proper (eqm ==> eqm) Z.opp. Proof. intros x y H. change ((-x)==(-y)) with ((0-x)==(0-y)). now rewrite H. Qed. Lemma Zmod_eqm : forall a, (a mod N) == a. Proof. intros; exact (Zmod_mod a N). Qed. (* NB: Z.modulo and Z.div are not morphisms with respect to eqm. For instance, let (==) be (eqm 2). Then we have (3 == 1) but: ~ (3 mod 3 == 1 mod 3) ~ (1 mod 3 == 1 mod 1) ~ (3/3 == 1/3) ~ (1/3 == 1/1) *) End EqualityModulo. Lemma Zdiv_Zdiv : forall a b c, 0<=b -> 0<=c -> (a/b)/c = a/(b*c). Proof. intros. zero_or_not b. rewrite Z.mul_comm. zero_or_not c. rewrite Z.mul_comm. apply Z.div_div; auto with zarith. Qed. (** Unfortunately, the previous result isn't always true on negative numbers. For instance: 3/(-2)/(-2) = 1 <> 0 = 3 / (-2*-2) *) (** A last inequality: *) Theorem Zdiv_mult_le: forall a b c, 0<=a -> 0<=b -> 0<=c -> c*(a/b) <= (c*a)/b. Proof. intros. zero_or_not b. apply Z.div_mul_le; auto with zarith. Qed. (** Z.modulo is related to divisibility (see more in Znumtheory) *) Lemma Zmod_divides : forall a b, b<>0 -> (a mod b = 0 <-> exists c, a = b*c). Proof. intros. rewrite Z.mod_divide; trivial. split; intros (c,Hc); exists c; subst; auto with zarith. Qed. (** Particular case : dividing by 2 is related with parity *) Lemma Zdiv2_div : forall a, Z.div2 a = a/2. Proof Z.div2_div. Lemma Zmod_odd : forall a, a mod 2 = if Z.odd a then 1 else 0. Proof. intros a. now rewrite <- Z.bit0_odd, <- Z.bit0_mod. Qed. Lemma Zmod_even : forall a, a mod 2 = if Z.even a then 0 else 1. Proof. intros a. rewrite Zmod_odd, Zodd_even_bool. now destruct Z.even. Qed. Lemma Zodd_mod : forall a, Z.odd a = Zeq_bool (a mod 2) 1. Proof. intros a. rewrite Zmod_odd. now destruct Z.odd. Qed. Lemma Zeven_mod : forall a, Z.even a = Zeq_bool (a mod 2) 0. Proof. intros a. rewrite Zmod_even. now destruct Z.even. Qed. (** * Compatibility *) (** Weaker results kept only for compatibility *) Lemma Z_mod_same : forall a, a > 0 -> a mod a = 0. Proof. intros; apply Z_mod_same_full. Qed. Lemma Z_div_same : forall a, a > 0 -> a/a = 1. Proof. intros; apply Z_div_same_full; auto with zarith. Qed. Lemma Z_div_plus : forall a b c:Z, c > 0 -> (a + b * c) / c = a / c + b. Proof. intros; apply Z_div_plus_full; auto with zarith. Qed. Lemma Z_div_mult : forall a b:Z, b > 0 -> (a*b)/b = a. Proof. intros; apply Z_div_mult_full; auto with zarith. Qed. Lemma Z_mod_plus : forall a b c:Z, c > 0 -> (a + b * c) mod c = a mod c. Proof. intros; apply Z_mod_plus_full; auto with zarith. Qed. Lemma Z_div_exact_1 : forall a b:Z, b > 0 -> a = b*(a/b) -> a mod b = 0. Proof. intros; apply Z_div_exact_full_1; auto with zarith. Qed. Lemma Z_div_exact_2 : forall a b:Z, b > 0 -> a mod b = 0 -> a = b*(a/b). Proof. intros; apply Z_div_exact_full_2; auto with zarith. Qed. Lemma Z_mod_zero_opp : forall a b:Z, b > 0 -> a mod b = 0 -> (-a) mod b = 0. Proof. intros; apply Z_mod_zero_opp_full; auto with zarith. Qed. (** * A direct way to compute Z.modulo *) Fixpoint Zmod_POS (a : positive) (b : Z) : Z := match a with | xI a' => let r := Zmod_POS a' b in let r' := (2 * r + 1) in if r' <? b then r' else (r' - b) | xO a' => let r := Zmod_POS a' b in let r' := (2 * r) in if r' <? b then r' else (r' - b) | xH => if 2 <=? b then 1 else 0 end. Definition Zmod' a b := match a with | Z0 => 0 | Zpos a' => match b with | Z0 => 0 | Zpos _ => Zmod_POS a' b | Zneg b' => let r := Zmod_POS a' (Zpos b') in match r with Z0 => 0 | _ => b + r end end | Zneg a' => match b with | Z0 => 0 | Zpos _ => let r := Zmod_POS a' b in match r with Z0 => 0 | _ => b - r end | Zneg b' => - (Zmod_POS a' (Zpos b')) end end. Theorem Zmod_POS_correct a b : Zmod_POS a b = snd (Z.pos_div_eucl a b). Proof. induction a as [a IH|a IH| ]; simpl; rewrite ?IH. destruct (Z.pos_div_eucl a b) as (p,q); simpl; case Z.ltb_spec; reflexivity. destruct (Z.pos_div_eucl a b) as (p,q); simpl; case Z.ltb_spec; reflexivity. case Z.leb_spec; trivial. Qed. Theorem Zmod'_correct: forall a b, Zmod' a b = a mod b. Proof. intros a b; unfold Z.modulo; case a; simpl; auto. intros p; case b; simpl; auto. intros p1; refine (Zmod_POS_correct _ _); auto. intros p1; rewrite Zmod_POS_correct; auto. case (Z.pos_div_eucl p (Zpos p1)); simpl; intros z1 z2; case z2; auto. intros p; case b; simpl; auto. intros p1; rewrite Zmod_POS_correct; auto. case (Z.pos_div_eucl p (Zpos p1)); simpl; intros z1 z2; case z2; auto. intros p1; rewrite Zmod_POS_correct; simpl; auto. case (Z.pos_div_eucl p (Zpos p1)); auto. Qed. (** Another convention is possible for division by negative numbers: * quotient is always the biggest integer smaller than or equal to a/b * remainder is hence always positive or null. *) Theorem Zdiv_eucl_extended : forall b:Z, b <> 0 -> forall a:Z, {qr : Z * Z | let (q, r) := qr in a = b * q + r /\ 0 <= r < Z.abs b}. Proof. intros b Hb a. destruct (Z_le_gt_dec 0 b) as [Hb'|Hb']. - assert (Hb'' : b > 0) by omega. rewrite Z.abs_eq; [ apply Zdiv_eucl_exist; assumption | assumption ]. - assert (Hb'' : - b > 0) by omega. destruct (Zdiv_eucl_exist Hb'' a) as ((q,r),[]). exists (- q, r). split. + rewrite <- Z.mul_opp_comm; assumption. + rewrite Z.abs_neq; [ assumption | omega ]. Qed. Arguments Zdiv_eucl_extended : default implicits. (** * Division and modulo in Z agree with same in nat: *) Require Import PeanoNat. Lemma div_Zdiv (n m: nat): m <> O -> Z.of_nat (n / m) = Z.of_nat n / Z.of_nat m. Proof. intros. apply (Zdiv_unique _ _ _ (Z.of_nat (n mod m))). split. auto with zarith. now apply inj_lt, Nat.mod_upper_bound. rewrite <- Nat2Z.inj_mul, <- Nat2Z.inj_add. now apply inj_eq, Nat.div_mod. Qed. Lemma mod_Zmod (n m: nat): m <> O -> Z.of_nat (n mod m) = (Z.of_nat n) mod (Z.of_nat m). Proof. intros. apply (Zmod_unique _ _ (Z.of_nat n / Z.of_nat m)). split. auto with zarith. now apply inj_lt, Nat.mod_upper_bound. rewrite <- div_Zdiv, <- Nat2Z.inj_mul, <- Nat2Z.inj_add by trivial. now apply inj_eq, Nat.div_mod. Qed.
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * 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. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // 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 REGENTS OF THE // UNIVERSITY OF CALIFORNIA 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. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: rxr_engine_classic.v // Version: 1.0 // Verilog Standard: Verilog-2001 // Description: The RXR Engine (Classic) takes a single stream of TLP // packets and provides the request packets on the RXR Interface. // This Engine is capable of operating at "line rate". // Author: Dustin Richmond (@darichmond) //----------------------------------------------------------------------------- `timescale 1ns/1ns `include "trellis.vh" `include "tlp.vh" module rxr_engine_classic #(parameter C_VENDOR = "ALTERA", parameter C_PCI_DATA_WIDTH = 128, parameter C_RX_PIPELINE_DEPTH=10) (// Interface: Clocks input CLK, // Interface: Resets input RST_BUS, // Replacement for generic RST_IN input RST_LOGIC, // Addition for RIFFA_RST output DONE_RXR_RST, // Interface: RX Classic input [C_PCI_DATA_WIDTH-1:0] RX_TLP, input RX_TLP_VALID, input RX_TLP_START_FLAG, input [`SIG_OFFSET_W-1:0] RX_TLP_START_OFFSET, input RX_TLP_END_FLAG, input [`SIG_OFFSET_W-1:0] RX_TLP_END_OFFSET, input [`SIG_BARDECODE_W-1:0] RX_TLP_BAR_DECODE, // Interface: RXR output [C_PCI_DATA_WIDTH-1:0] RXR_DATA, output RXR_DATA_VALID, output [(C_PCI_DATA_WIDTH/32)-1:0] RXR_DATA_WORD_ENABLE, output RXR_DATA_START_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] RXR_DATA_START_OFFSET, output RXR_DATA_END_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] RXR_DATA_END_OFFSET, output [`SIG_FBE_W-1:0] RXR_META_FDWBE, output [`SIG_LBE_W-1:0] RXR_META_LDWBE, output [`SIG_TC_W-1:0] RXR_META_TC, output [`SIG_ATTR_W-1:0] RXR_META_ATTR, output [`SIG_TAG_W-1:0] RXR_META_TAG, output [`SIG_TYPE_W-1:0] RXR_META_TYPE, output [`SIG_ADDR_W-1:0] RXR_META_ADDR, output [`SIG_BARDECODE_W-1:0] RXR_META_BAR_DECODED, output [`SIG_REQID_W-1:0] RXR_META_REQUESTER_ID, output [`SIG_LEN_W-1:0] RXR_META_LENGTH, output RXR_META_EP, // Interface: RX Shift Register input [(C_RX_PIPELINE_DEPTH+1)*C_PCI_DATA_WIDTH-1:0] RX_SR_DATA, input [C_RX_PIPELINE_DEPTH:0] RX_SR_EOP, input [(C_RX_PIPELINE_DEPTH+1)*`SIG_OFFSET_W-1:0] RX_SR_END_OFFSET, input [C_RX_PIPELINE_DEPTH:0] RX_SR_SOP, input [C_RX_PIPELINE_DEPTH:0] RX_SR_VALID ); /*AUTOWIRE*/ ///*AUTOOUTPUT*/ // End of automatics localparam C_RX_BE_W = (`SIG_FBE_W+`SIG_LBE_W); localparam C_RX_INPUT_STAGES = 1; localparam C_RX_OUTPUT_STAGES = 1; // Must always be at least one localparam C_RX_COMPUTATION_STAGES = 1; localparam C_TOTAL_STAGES = C_RX_COMPUTATION_STAGES + C_RX_OUTPUT_STAGES + C_RX_INPUT_STAGES; // Cycle index in the SOP register when enable is raised // Computation can begin when the last DW of the header is recieved. localparam C_RX_COMPUTATION_CYCLE = C_RX_COMPUTATION_STAGES + (`TLP_REQADDRDW1_I/C_PCI_DATA_WIDTH) + C_RX_INPUT_STAGES; // The computation cycle must be at least one cycle before the address is enabled localparam C_RX_DATA_CYCLE = C_RX_COMPUTATION_CYCLE; localparam C_RX_ADDRDW0_CYCLE = (`TLP_REQADDRDW0_I/C_PCI_DATA_WIDTH) + C_RX_INPUT_STAGES; localparam C_RX_ADDRDW1_CYCLE = (`TLP_REQADDRDW1_I/C_PCI_DATA_WIDTH) + C_RX_INPUT_STAGES; localparam C_RX_METADW0_CYCLE = (`TLP_REQMETADW0_I/C_PCI_DATA_WIDTH) + C_RX_INPUT_STAGES; localparam C_RX_METADW1_CYCLE = (`TLP_REQMETADW1_I/C_PCI_DATA_WIDTH) + C_RX_INPUT_STAGES; localparam C_RX_ADDRDW0_INDEX = C_PCI_DATA_WIDTH*C_RX_INPUT_STAGES + (`TLP_REQADDRDW0_I%C_PCI_DATA_WIDTH); localparam C_RX_ADDRDW1_INDEX = C_PCI_DATA_WIDTH*C_RX_INPUT_STAGES + (`TLP_REQADDRDW1_I%C_PCI_DATA_WIDTH); localparam C_RX_ADDRDW1_RESET_INDEX = C_PCI_DATA_WIDTH*C_RX_INPUT_STAGES + C_PCI_DATA_WIDTH*(C_RX_ADDRDW1_CYCLE - C_RX_METADW0_CYCLE) + `TLP_4DWHBIT_I; localparam C_RX_METADW0_INDEX = C_PCI_DATA_WIDTH*C_RX_INPUT_STAGES + (`TLP_REQMETADW0_I%C_PCI_DATA_WIDTH); localparam C_RX_METADW1_INDEX = C_PCI_DATA_WIDTH*C_RX_INPUT_STAGES + (`TLP_REQMETADW1_I%C_PCI_DATA_WIDTH); localparam C_OFFSET_WIDTH = clog2s(C_PCI_DATA_WIDTH/32); localparam C_MAX_ABLANK_WIDTH = 32; localparam C_MAX_START_OFFSET = (`TLP_MAXHDR_W + C_MAX_ABLANK_WIDTH)/32; localparam C_STD_START_DELAY = (64/C_PCI_DATA_WIDTH); wire [63:0] wAddrFmt; wire [63:0] wMetadata; wire [`TLP_TYPE_W-1:0] wType; wire [`TLP_LEN_W-1:0] wLength; wire wAddrDW0Bit2; wire wAddrDW1Bit2; wire wAddrHiReset; wire [31:0] wAddrMux[(`TLP_REQADDR_W / 32)-1:0]; wire [63:0] wAddr; wire w4DWH; wire wHasPayload; wire [2:0] wHdrLength; wire [2:0] wHdrLengthM1; wire [(C_PCI_DATA_WIDTH/32)-1:0] wEndMask; wire _wEndFlag; wire wEndFlag; wire [C_OFFSET_WIDTH-1:0] wEndOffset; wire [(C_PCI_DATA_WIDTH/32)-1:0] wStartMask; wire [3:0] wStartFlags; wire wStartFlag; wire _wStartFlag; wire [clog2s(C_MAX_START_OFFSET)-1:0] wStartOffset; wire wInsertBlank; wire wRotateAddressField; wire [C_PCI_DATA_WIDTH-1:0] wRxrData; wire [`SIG_ADDR_W-1:0] wRxrMetaAddr; wire [63:0] wRxrMetadata; wire wRxrDataValid; wire wRxrDataReady; // Pinned High wire wRxrDataEndFlag; wire [C_OFFSET_WIDTH-1:0] wRxrDataEndOffset; wire [(C_PCI_DATA_WIDTH/32)-1:0] wRxrDataWordEnable; wire wRxrDataStartFlag; wire [C_OFFSET_WIDTH-1:0] wRxrDataStartOffset; wire [C_RX_PIPELINE_DEPTH:0] wRxSrSop; reg rValid,_rValid; reg rRST; assign DONE_RXR_RST = ~rRST; assign wAddrHiReset = ~RX_SR_DATA[C_RX_ADDRDW1_RESET_INDEX]; // Select Addr[31:0] from one of the two possible locations in the TLP based // on header length (1 bit) assign wRotateAddressField = w4DWH; assign wAddrFmt = {wAddrMux[~wRotateAddressField],wAddrMux[wRotateAddressField]}; assign wAddrMux[0] = wAddr[31:0]; assign wAddrMux[1] = wAddr[63:32]; // Calculate the header length (start offset), and header length minus 1 (end offset) assign wHdrLength = {w4DWH,~w4DWH,~w4DWH}; assign wHdrLengthM1 = {1'b0,1'b1,w4DWH}; // Determine if the TLP has an inserted blank before the payload assign wInsertBlank = ((w4DWH & wAddrDW1Bit2) | (~w4DWH & ~wAddrDW0Bit2)) & (C_VENDOR == "ALTERA"); assign wStartOffset = (wHdrLength + {2'd0,wInsertBlank}); // Start offset in dwords assign wEndOffset = wHdrLengthM1 + wInsertBlank + wLength;//RX_SR_END_OFFSET[(C_TOTAL_STAGES-1)*`SIG_OFFSET_W +: C_OFFSET_WIDTH]; // Inputs // Technically an input, but the trellis protocol specifies it must be held high at all times assign wRxrDataReady = 1; // Outputs assign RXR_DATA = RX_SR_DATA[(C_TOTAL_STAGES)*C_PCI_DATA_WIDTH +: C_PCI_DATA_WIDTH]; assign RXR_DATA_VALID = wRxrDataValid; assign RXR_DATA_END_FLAG = wRxrDataEndFlag; assign RXR_DATA_END_OFFSET = wRxrDataEndOffset; assign RXR_DATA_START_FLAG = wRxrDataStartFlag; assign RXR_DATA_START_OFFSET = wRxrDataStartOffset; assign RXR_META_BAR_DECODED = 0; assign RXR_META_LENGTH = wRxrMetadata[`TLP_LEN_R]; assign RXR_META_TC = wRxrMetadata[`TLP_TC_R]; assign RXR_META_ATTR = {wRxrMetadata[`TLP_ATTR1_R], wRxrMetadata[`TLP_ATTR0_R]}; assign RXR_META_TYPE = tlp_to_trellis_type({wRxrMetadata[`TLP_FMT_R],wRxrMetadata[`TLP_TYPE_R]}); assign RXR_META_ADDR = wRxrMetaAddr; assign RXR_META_REQUESTER_ID = wRxrMetadata[`TLP_REQREQID_R]; assign RXR_META_TAG = wRxrMetadata[`TLP_REQTAG_R]; assign RXR_META_FDWBE = wRxrMetadata[`TLP_REQFBE_R]; assign RXR_META_LDWBE = wRxrMetadata[`TLP_REQLBE_R]; assign RXR_META_EP = wRxrMetadata[`TLP_EP_R]; assign _wEndFlag = RX_SR_EOP[C_RX_INPUT_STAGES]; assign wEndFlag = RX_SR_EOP[C_RX_INPUT_STAGES+1]; assign _wStartFlag = wStartFlags != 0; generate if(C_PCI_DATA_WIDTH == 32) begin assign wStartFlags[3] = 0; assign wStartFlags[2] = wRxSrSop[C_RX_INPUT_STAGES + 3] & wMetadata[`TLP_PAYBIT_I] & ~rValid; // Any remaining cases assign wStartFlags[1] = wRxSrSop[C_RX_INPUT_STAGES + 2] & wMetadata[`TLP_PAYBIT_I] & ~wMetadata[`TLP_4DWHBIT_I]; // 3DWH, No Blank assign wStartFlags[0] = wRxSrSop[C_RX_INPUT_STAGES + 2] & ~wMetadata[`TLP_PAYBIT_I]; // No Payload end else if(C_PCI_DATA_WIDTH == 64) begin assign wStartFlags[3] = 0; assign wStartFlags[2] = wRxSrSop[C_RX_INPUT_STAGES + 2] & wMetadata[`TLP_PAYBIT_I] & ~rValid; // Any remaining cases if(C_VENDOR == "ALTERA") begin assign wStartFlags[1] = wRxSrSop[C_RX_INPUT_STAGES + 1] & wMetadata[`TLP_PAYBIT_I] & ~wMetadata[`TLP_4DWHBIT_I] & RX_SR_DATA[C_RX_ADDRDW0_INDEX + 2]; // 3DWH, No Blank end else begin assign wStartFlags[1] = wRxSrSop[C_RX_INPUT_STAGES + 1] & wMetadata[`TLP_PAYBIT_I] & ~wMetadata[`TLP_4DWHBIT_I]; // 3DWH, No Blank end assign wStartFlags[0] = wRxSrSop[C_RX_INPUT_STAGES + 1] & ~wMetadata[`TLP_PAYBIT_I]; // No Payload end else if (C_PCI_DATA_WIDTH == 128) begin assign wStartFlags[3] = 0; assign wStartFlags[2] = wRxSrSop[C_RX_INPUT_STAGES + 1] & wMetadata[`TLP_PAYBIT_I] & ~rValid; // Is this correct? if(C_VENDOR == "ALTERA") begin assign wStartFlags[1] = wRxSrSop[C_RX_INPUT_STAGES] & RX_SR_DATA[C_RX_METADW0_INDEX + `TLP_PAYBIT_I] & ~RX_SR_DATA[C_RX_METADW0_INDEX + `TLP_4DWHBIT_I] & RX_SR_DATA[C_RX_ADDRDW0_INDEX + 2]; // 3DWH, No Blank end else begin assign wStartFlags[1] = wRxSrSop[C_RX_INPUT_STAGES] & RX_SR_DATA[C_RX_METADW0_INDEX + `TLP_PAYBIT_I] & ~RX_SR_DATA[C_RX_METADW0_INDEX + `TLP_4DWHBIT_I]; end assign wStartFlags[0] = wRxSrSop[C_RX_INPUT_STAGES] & ~RX_SR_DATA[C_RX_METADW0_INDEX + `TLP_PAYBIT_I]; // No Payload end else begin // 256 assign wStartFlags[3] = 0; assign wStartFlags[2] = 0; assign wStartFlags[1] = 0; assign wStartFlags[0] = wRxSrSop[C_RX_INPUT_STAGES]; end // else: !if(C_PCI_DATA_WIDTH == 128) endgenerate always @(*) begin _rValid = rValid; if(_wStartFlag) begin _rValid = 1'b1; end else if (wEndFlag) begin _rValid = 1'b0; end end always @(posedge CLK) begin if(rRST) begin rValid <= 1'b0; end else begin rValid <= _rValid; end end always @(posedge CLK) begin rRST <= RST_BUS | RST_LOGIC; end assign wStartMask = {C_PCI_DATA_WIDTH/32{1'b1}} << ({C_OFFSET_WIDTH{wStartFlag}}& wStartOffset[C_OFFSET_WIDTH-1:0]); offset_to_mask #(// Parameters .C_MASK_SWAP (0), .C_MASK_WIDTH (C_PCI_DATA_WIDTH/32) /*AUTOINSTPARAM*/) o2m_ef ( // Outputs .MASK (wEndMask), // Inputs .OFFSET_ENABLE (wEndFlag), .OFFSET (wEndOffset[C_OFFSET_WIDTH-1:0]) /*AUTOINST*/); generate if(C_RX_OUTPUT_STAGES == 0) begin assign RXR_DATA_WORD_ENABLE = {wEndMask & wStartMask} & {C_PCI_DATA_WIDTH/32{~rValid | ~wMetadata[`TLP_PAYBIT_I]}}; end else begin register #( // Parameters .C_WIDTH (C_PCI_DATA_WIDTH/32), .C_VALUE (0) /*AUTOINSTPARAM*/) dw_enable (// Outputs .RD_DATA (wRxrDataWordEnable), // Inputs .RST_IN (~rValid | ~wMetadata[`TLP_PAYBIT_I]), .WR_DATA (wEndMask & wStartMask), .WR_EN (1), /*AUTOINST*/ // Inputs .CLK (CLK)); pipeline #( // Parameters .C_DEPTH (C_RX_OUTPUT_STAGES-1), .C_WIDTH (C_PCI_DATA_WIDTH/32), .C_USE_MEMORY (0) /*AUTOINSTPARAM*/) dw_pipeline (// Outputs .WR_DATA_READY (), // Pinned to 1 .RD_DATA (RXR_DATA_WORD_ENABLE), .RD_DATA_VALID (), // Inputs .WR_DATA (wRxrDataWordEnable), .WR_DATA_VALID (1), .RD_DATA_READY (1'b1), .RST_IN (rRST), /*AUTOINST*/ // Inputs .CLK (CLK)); end endgenerate register #( // Parameters .C_WIDTH (32), .C_VALUE (0) /*AUTOINSTPARAM*/) metadata_DW0_register ( // Outputs .RD_DATA (wMetadata[31:0]), // Inputs .WR_DATA (RX_SR_DATA[C_RX_METADW0_INDEX +: 32]), .WR_EN (wRxSrSop[C_RX_METADW0_CYCLE]), .RST_IN (rRST), /*AUTOINST*/ // Inputs .CLK (CLK)); register #(// Parameters .C_WIDTH (32), .C_VALUE (0) /*AUTOINSTPARAM*/) meta_DW1_register (// Outputs .RD_DATA (wMetadata[63:32]), // Inputs .WR_DATA (RX_SR_DATA[C_RX_METADW1_INDEX +: 32]), .WR_EN (wRxSrSop[C_RX_METADW1_CYCLE]), .RST_IN (rRST), /*AUTOINST*/ // Inputs .CLK (CLK)); register #(// Parameters .C_WIDTH (32), .C_VALUE (0) /*AUTOINSTPARAM*/) addr_DW0_register (// Outputs .RD_DATA (wAddr[31:0]), // Inputs .WR_DATA (RX_SR_DATA[C_RX_ADDRDW0_INDEX +: 32]), .WR_EN (wRxSrSop[C_RX_ADDRDW0_CYCLE]), .RST_IN (0), /*AUTOINST*/ // Inputs .CLK (CLK)); register #(// Parameters .C_WIDTH (32), .C_VALUE (0) /*AUTOINSTPARAM*/) addr_DW1_register (// Outputs .RD_DATA (wAddr[63:32]), // Inputs .WR_DATA (RX_SR_DATA[C_RX_ADDRDW1_INDEX +: 32]), .WR_EN (wRxSrSop[C_RX_ADDRDW1_CYCLE]), .RST_IN (wAddrHiReset & wRxSrSop[C_RX_ADDRDW1_CYCLE]), /*AUTOINST*/ // Inputs .CLK (CLK)); register #(// Parameters .C_WIDTH (2), .C_VALUE (0) /*AUTOINSTPARAM*/) metadata_4DWH_register (// Outputs .RD_DATA ({wHasPayload,w4DWH}), // Inputs .WR_DATA (RX_SR_DATA[`TLP_FMT_I + C_PCI_DATA_WIDTH*C_RX_INPUT_STAGES +: 2]), .WR_EN (wRxSrSop[`TLP_4DWHBIT_I/C_PCI_DATA_WIDTH + C_RX_INPUT_STAGES]), .RST_IN (0), /*AUTOINST*/ // Inputs .CLK (CLK)); register #(// Parameters .C_WIDTH (`TLP_TYPE_W), .C_VALUE (0) /*AUTOINSTPARAM*/) metadata_type_register (// Outputs .RD_DATA (wType), // Inputs .WR_DATA (RX_SR_DATA[(`TLP_TYPE_I/* + C_PCI_DATA_WIDTH*C_RX_INPUT_STAGES*/) +: `TLP_TYPE_W]), .WR_EN (wRxSrSop[`TLP_TYPE_I/C_PCI_DATA_WIDTH/* + C_RX_INPUT_STAGES*/]), .RST_IN (0), /*AUTOINST*/ // Inputs .CLK (CLK)); register #(// Parameters .C_WIDTH (`TLP_LEN_W), .C_VALUE (0) /*AUTOINSTPARAM*/) metadata_length_register (// Outputs .RD_DATA (wLength), // Inputs .WR_DATA (RX_SR_DATA[(`TLP_LEN_I + C_PCI_DATA_WIDTH*C_RX_INPUT_STAGES) +: `TLP_LEN_W]), .WR_EN (wRxSrSop[`TLP_LEN_I/C_PCI_DATA_WIDTH + C_RX_INPUT_STAGES]), .RST_IN (0), /*AUTOINST*/ // Inputs .CLK (CLK)); register #(// Parameters .C_WIDTH (1), .C_VALUE (0) /*AUTOINSTPARAM*/) addr_DW0_bit_2_register (// Outputs .RD_DATA (wAddrDW0Bit2), // Inputs .RST_IN (0), .WR_DATA (RX_SR_DATA[(`TLP_REQADDRDW0_I%C_PCI_DATA_WIDTH) + 2 + C_PCI_DATA_WIDTH*C_RX_INPUT_STAGES]), .WR_EN (wRxSrSop[(`TLP_REQADDRDW0_I/C_PCI_DATA_WIDTH) + C_RX_INPUT_STAGES]), /*AUTOINST*/ // Inputs .CLK (CLK)); register #(// Parameters .C_WIDTH (1), .C_VALUE (0) /*AUTOINSTPARAM*/) addr_DW1_bit_2_register (// Outputs .RD_DATA (wAddrDW1Bit2), // Inputs .WR_DATA (RX_SR_DATA[(`TLP_REQADDRDW1_I%C_PCI_DATA_WIDTH) + 2 + C_PCI_DATA_WIDTH*C_RX_INPUT_STAGES]), .WR_EN (wRxSrSop[(`TLP_REQADDRDW1_I/C_PCI_DATA_WIDTH) + C_RX_INPUT_STAGES]), .RST_IN (0), /*AUTOINST*/ // Inputs .CLK (CLK)); register #(// Parameters .C_WIDTH (1), .C_VALUE (0) /*AUTOINSTPARAM*/) start_flag_register (// Outputs .RD_DATA (wStartFlag), // Inputs .WR_DATA (_wStartFlag), .WR_EN (1), .RST_IN (0), /*AUTOINST*/ // Inputs .CLK (CLK)); pipeline #(// Parameters .C_DEPTH (C_RX_OUTPUT_STAGES), .C_WIDTH (`TLP_MAXHDR_W + 2*(1 + C_OFFSET_WIDTH)), .C_USE_MEMORY (0) /*AUTOINSTPARAM*/) output_pipeline (// Outputs .WR_DATA_READY (), // Pinned to 1 .RD_DATA ({wRxrMetadata,wRxrMetaAddr,wRxrDataStartFlag,wRxrDataStartOffset,wRxrDataEndFlag,wRxrDataEndOffset}), .RD_DATA_VALID (wRxrDataValid), // Inputs .WR_DATA ({wMetadata, wAddrFmt, wStartFlag,wStartOffset[C_OFFSET_WIDTH-1:0],wEndFlag,wEndOffset[C_OFFSET_WIDTH-1:0]}), .WR_DATA_VALID (rValid & RX_SR_VALID[C_TOTAL_STAGES-C_RX_OUTPUT_STAGES]), .RD_DATA_READY (1'b1), .RST_IN (rRST), /*AUTOINST*/ // Inputs .CLK (CLK)); // Start Flag Shift Register. Data enables are derived from the // taps on this shift register. shiftreg #(// Parameters .C_DEPTH (C_RX_PIPELINE_DEPTH), .C_WIDTH (1'b1), .C_VALUE (0) /*AUTOINSTPARAM*/) sop_shiftreg_inst (// Outputs .RD_DATA (wRxSrSop), // Inputs .WR_DATA (RX_TLP_START_FLAG & RX_TLP_VALID & (RX_SR_DATA[`TLP_TYPE_R] == `TLP_TYPE_REQ)), .RST_IN (0), /*AUTOINST*/ // Inputs .CLK (CLK)); endmodule // Local Variables: // verilog-library-directories:("." "../../../common") // End:
//***************************************************************************** // (c) Copyright 2009 - 2013 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_phy_ck_addr_cmd_delay.v // /___/ /\ Date Last Modified: $Date: 2011/02/25 02:07:40 $ // \ \ / \ Date Created: Aug 03 2009 // \___\/\___\ // //Device: 7 Series //Design Name: DDR3 SDRAM //Purpose: Shift CK/Address/Commands/Controls //Reference: //Revision History: //***************************************************************************** `timescale 1ps/1ps module mig_7series_v1_9_ddr_phy_ck_addr_cmd_delay # ( parameter TCQ = 100, parameter tCK = 3636, parameter DQS_CNT_WIDTH = 3, parameter N_CTL_LANES = 3, parameter SIM_CAL_OPTION = "NONE" ) ( input clk, input rst, // Start only after PO_CIRC_BUF_DELAY decremented input cmd_delay_start, // Control lane being shifted using Phaser_Out fine delay taps output reg [N_CTL_LANES-1:0] ctl_lane_cnt, // Inc/dec Phaser_Out fine delay line output reg po_stg2_f_incdec, output reg po_en_stg2_f, output reg po_stg2_c_incdec, output reg po_en_stg2_c, // Completed delaying CK/Address/Commands/Controls output po_ck_addr_cmd_delay_done ); localparam TAP_CNT_LIMIT = 63; //Calculate the tap resolution of the PHASER based on the clock period localparam FREQ_REF_DIV = (tCK > 5000 ? 4 : tCK > 2500 ? 2 : 1); localparam integer PHASER_TAP_RES = ((tCK/2)/64); // Determine whether 300 ps or 350 ps delay required localparam CALC_TAP_CNT = (tCK >= 1250) ? 350 : 300; // Determine the number of Phaser_Out taps required to delay by 300 ps // 300 ps is the PCB trace uncertainty between CK and DQS byte groups // Increment control byte lanes localparam TAP_CNT = 0; //localparam TAP_CNT = (CALC_TAP_CNT + PHASER_TAP_RES - 1)/PHASER_TAP_RES; //Decrement control byte lanes localparam TAP_DEC = (SIM_CAL_OPTION == "FAST_CAL") ? 0 : 29; reg delay_dec_done; reg delay_done_r1; reg delay_done_r2; reg delay_done_r3; (* keep = "true", max_fanout = 10 *) reg delay_done_r4 /* synthesis syn_maxfan = 10 */; reg [5:0] delay_cnt_r; reg [5:0] delaydec_cnt_r; reg po_cnt_inc; reg po_cnt_dec; reg [3:0] wait_cnt_r; assign po_ck_addr_cmd_delay_done = ((TAP_CNT == 0) && (TAP_DEC == 0)) ? 1'b1 : delay_done_r4; always @(posedge clk) begin if (rst || po_cnt_dec || po_cnt_inc) wait_cnt_r <= #TCQ 'd8; else if (cmd_delay_start && (wait_cnt_r > 'd0)) wait_cnt_r <= #TCQ wait_cnt_r - 1; end always @(posedge clk) begin if (rst || (delaydec_cnt_r > 6'd0) || (delay_cnt_r == 'd0) || (TAP_DEC == 0)) po_cnt_inc <= #TCQ 1'b0; else if ((delay_cnt_r > 'd0) && (wait_cnt_r == 'd1)) po_cnt_inc <= #TCQ 1'b1; else po_cnt_inc <= #TCQ 1'b0; end //Tap decrement always @(posedge clk) begin if (rst || (delaydec_cnt_r == 'd0)) po_cnt_dec <= #TCQ 1'b0; else if (cmd_delay_start && (delaydec_cnt_r > 'd0) && (wait_cnt_r == 'd1)) po_cnt_dec <= #TCQ 1'b1; else po_cnt_dec <= #TCQ 1'b0; end //po_stg2_f_incdec and po_en_stg2_f stay asserted HIGH for TAP_COUNT cycles for every control byte lane //the alignment is started once the always @(posedge clk) begin if (rst) begin po_stg2_f_incdec <= #TCQ 1'b0; po_en_stg2_f <= #TCQ 1'b0; po_stg2_c_incdec <= #TCQ 1'b0; po_en_stg2_c <= #TCQ 1'b0; end else begin if (po_cnt_dec) begin po_stg2_f_incdec <= #TCQ 1'b0; po_en_stg2_f <= #TCQ 1'b1; end else begin po_stg2_f_incdec <= #TCQ 1'b0; po_en_stg2_f <= #TCQ 1'b0; end if (po_cnt_inc) begin po_stg2_c_incdec <= #TCQ 1'b1; po_en_stg2_c <= #TCQ 1'b1; end else begin po_stg2_c_incdec <= #TCQ 1'b0; po_en_stg2_c <= #TCQ 1'b0; end end end // delay counter to count 2 cycles // Increment coarse taps by 2 for all control byte lanes // to mitigate late writes always @(posedge clk) begin // load delay counter with init value if (rst || (tCK > 2500) || (SIM_CAL_OPTION == "FAST_CAL")) delay_cnt_r <= #TCQ 'd0; else if ((delaydec_cnt_r > 6'd0) ||((delay_cnt_r == 6'd0) && (ctl_lane_cnt != N_CTL_LANES-1))) delay_cnt_r <= #TCQ 'd1; else if (po_cnt_inc && (delay_cnt_r > 6'd0)) delay_cnt_r <= #TCQ delay_cnt_r - 1; end // delay counter to count TAP_DEC cycles always @(posedge clk) begin // load delay counter with init value of TAP_DEC if (rst || ~cmd_delay_start ||((delaydec_cnt_r == 6'd0) && (delay_cnt_r == 6'd0) && (ctl_lane_cnt != N_CTL_LANES-1))) delaydec_cnt_r <= #TCQ TAP_DEC; else if (po_cnt_dec && (delaydec_cnt_r > 6'd0)) delaydec_cnt_r <= #TCQ delaydec_cnt_r - 1; end //ctl_lane_cnt is used to count the number of CTL_LANES or byte lanes that have the address/command phase shifted by 1/4 mem. cycle //This ensures all ctrl byte lanes have had their output phase shifted. always @(posedge clk) begin if (rst || ~cmd_delay_start ) ctl_lane_cnt <= #TCQ 6'b0; else if (~delay_dec_done && (ctl_lane_cnt == N_CTL_LANES-1) && (delaydec_cnt_r == 6'd1)) ctl_lane_cnt <= #TCQ ctl_lane_cnt; else if ((ctl_lane_cnt != N_CTL_LANES-1) && (delaydec_cnt_r == 6'd0) && (delay_cnt_r == 'd0)) ctl_lane_cnt <= #TCQ ctl_lane_cnt + 1; end // All control lanes have decremented to 31 fine taps from 46 always @(posedge clk) begin if (rst || ~cmd_delay_start) begin delay_dec_done <= #TCQ 1'b0; end else if (((TAP_CNT == 0) && (TAP_DEC == 0)) || ((delaydec_cnt_r == 6'd0) && (delay_cnt_r == 'd0) && (ctl_lane_cnt == N_CTL_LANES-1))) begin delay_dec_done <= #TCQ 1'b1; end end always @(posedge clk) begin delay_done_r1 <= #TCQ delay_dec_done; delay_done_r2 <= #TCQ delay_done_r1; delay_done_r3 <= #TCQ delay_done_r2; delay_done_r4 <= #TCQ delay_done_r3; end endmodule
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * 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. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // 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 REGENTS OF THE // UNIVERSITY OF CALIFORNIA 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. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: engine_layer.v // Version: 1.0 // Verilog Standard: Verilog-2001 // Description: The engine layer encapsulates the RX and TX engines. // Author: Dustin Richmond (@darichmond) //----------------------------------------------------------------------------- `timescale 1ns/1ns `include "trellis.vh" `include "ultrascale.vh" module engine_layer #(parameter C_PCI_DATA_WIDTH = 128, parameter C_LOG_NUM_TAGS=6, parameter C_PIPELINE_INPUT = 1, parameter C_PIPELINE_OUTPUT = 0, parameter C_MAX_PAYLOAD_DWORDS = 64, parameter C_VENDOR="ULTRASCALE") (// Interface: Clocks input CLK_BUS, // Replacement for generic CLK // Interface: Resets input RST_BUS, // Replacement for generic RST_IN input RST_LOGIC, // Addition for RIFFA_RST output DONE_TXC_RST, output DONE_TXR_RST, output DONE_RXR_RST, output DONE_RXC_RST, // Interface: Configuration input [`SIG_CPLID_W-1:0] CONFIG_COMPLETER_ID, // Interface: RX Classic input [C_PCI_DATA_WIDTH-1:0] RX_TLP, input RX_TLP_VALID, input RX_TLP_START_FLAG, input [`SIG_OFFSET_W-1:0] RX_TLP_START_OFFSET, input RX_TLP_END_FLAG, input [`SIG_OFFSET_W-1:0] RX_TLP_END_OFFSET, input [`SIG_BARDECODE_W-1:0] RX_TLP_BAR_DECODE, output RX_TLP_READY, // Interface: TX Classic input TX_TLP_READY, output [C_PCI_DATA_WIDTH-1:0] TX_TLP, output TX_TLP_VALID, output TX_TLP_START_FLAG, output [`SIG_OFFSET_W-1:0] TX_TLP_START_OFFSET, output TX_TLP_END_FLAG, output [`SIG_OFFSET_W-1:0] TX_TLP_END_OFFSET, //Interface: CQ Ultrascale (RXR) input M_AXIS_CQ_TVALID, input M_AXIS_CQ_TLAST, input [C_PCI_DATA_WIDTH-1:0] M_AXIS_CQ_TDATA, input [(C_PCI_DATA_WIDTH/32)-1:0] M_AXIS_CQ_TKEEP, input [`SIG_CQ_TUSER_W-1:0] M_AXIS_CQ_TUSER, output M_AXIS_CQ_TREADY, //Interface: RC Ultrascale (RXC) input M_AXIS_RC_TVALID, input M_AXIS_RC_TLAST, input [C_PCI_DATA_WIDTH-1:0] M_AXIS_RC_TDATA, input [(C_PCI_DATA_WIDTH/32)-1:0] M_AXIS_RC_TKEEP, input [`SIG_RC_TUSER_W-1:0] M_AXIS_RC_TUSER, output M_AXIS_RC_TREADY, //Interface: CC Ultrascale (TXC) input S_AXIS_CC_TREADY, output S_AXIS_CC_TVALID, output S_AXIS_CC_TLAST, output [C_PCI_DATA_WIDTH-1:0] S_AXIS_CC_TDATA, output [(C_PCI_DATA_WIDTH/32)-1:0] S_AXIS_CC_TKEEP, output [`SIG_CC_TUSER_W-1:0] S_AXIS_CC_TUSER, //Interface: RQ Ultrascale (TXR) input S_AXIS_RQ_TREADY, output S_AXIS_RQ_TVALID, output S_AXIS_RQ_TLAST, output [C_PCI_DATA_WIDTH-1:0] S_AXIS_RQ_TDATA, output [(C_PCI_DATA_WIDTH/32)-1:0] S_AXIS_RQ_TKEEP, output [`SIG_RQ_TUSER_W-1:0] S_AXIS_RQ_TUSER, // Interface: RXC Engine output [C_PCI_DATA_WIDTH-1:0] RXC_DATA, output RXC_DATA_VALID, output [(C_PCI_DATA_WIDTH/32)-1:0] RXC_DATA_WORD_ENABLE, output RXC_DATA_START_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] RXC_DATA_START_OFFSET, output RXC_DATA_END_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] RXC_DATA_END_OFFSET, output [`SIG_LBE_W-1:0] RXC_META_LDWBE, output [`SIG_FBE_W-1:0] RXC_META_FDWBE, output [`SIG_TAG_W-1:0] RXC_META_TAG, output [`SIG_LOWADDR_W-1:0] RXC_META_ADDR, output [`SIG_TYPE_W-1:0] RXC_META_TYPE, output [`SIG_LEN_W-1:0] RXC_META_LENGTH, output [`SIG_BYTECNT_W-1:0] RXC_META_BYTES_REMAINING, output [`SIG_CPLID_W-1:0] RXC_META_COMPLETER_ID, output RXC_META_EP, // Interface: RXR Engine output [C_PCI_DATA_WIDTH-1:0] RXR_DATA, output RXR_DATA_VALID, output [(C_PCI_DATA_WIDTH/32)-1:0] RXR_DATA_WORD_ENABLE, output RXR_DATA_START_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] RXR_DATA_START_OFFSET, output RXR_DATA_END_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] RXR_DATA_END_OFFSET, output [`SIG_FBE_W-1:0] RXR_META_FDWBE, output [`SIG_LBE_W-1:0] RXR_META_LDWBE, output [`SIG_TC_W-1:0] RXR_META_TC, output [`SIG_ATTR_W-1:0] RXR_META_ATTR, output [`SIG_TAG_W-1:0] RXR_META_TAG, output [`SIG_TYPE_W-1:0] RXR_META_TYPE, output [`SIG_ADDR_W-1:0] RXR_META_ADDR, output [`SIG_BARDECODE_W-1:0] RXR_META_BAR_DECODED, output [`SIG_REQID_W-1:0] RXR_META_REQUESTER_ID, output [`SIG_LEN_W-1:0] RXR_META_LENGTH, output RXR_META_EP, // Interface: TXC Engine input TXC_DATA_VALID, input [C_PCI_DATA_WIDTH-1:0] TXC_DATA, input TXC_DATA_START_FLAG, input [clog2s(C_PCI_DATA_WIDTH/32)-1:0] TXC_DATA_START_OFFSET, input TXC_DATA_END_FLAG, input [clog2s(C_PCI_DATA_WIDTH/32)-1:0] TXC_DATA_END_OFFSET, output TXC_DATA_READY, input TXC_META_VALID, input [`SIG_FBE_W-1:0] TXC_META_FDWBE, input [`SIG_LBE_W-1:0] TXC_META_LDWBE, input [`SIG_LOWADDR_W-1:0] TXC_META_ADDR, input [`SIG_TYPE_W-1:0] TXC_META_TYPE, input [`SIG_LEN_W-1:0] TXC_META_LENGTH, input [`SIG_BYTECNT_W-1:0] TXC_META_BYTE_COUNT, input [`SIG_TAG_W-1:0] TXC_META_TAG, input [`SIG_REQID_W-1:0] TXC_META_REQUESTER_ID, input [`SIG_TC_W-1:0] TXC_META_TC, input [`SIG_ATTR_W-1:0] TXC_META_ATTR, input TXC_META_EP, output TXC_META_READY, output TXC_SENT, // Interface: TXR Engine input TXR_DATA_VALID, input [C_PCI_DATA_WIDTH-1:0] TXR_DATA, input TXR_DATA_START_FLAG, input [clog2s(C_PCI_DATA_WIDTH/32)-1:0] TXR_DATA_START_OFFSET, input TXR_DATA_END_FLAG, input [clog2s(C_PCI_DATA_WIDTH/32)-1:0] TXR_DATA_END_OFFSET, output TXR_DATA_READY, input TXR_META_VALID, input [`SIG_FBE_W-1:0] TXR_META_FDWBE, input [`SIG_LBE_W-1:0] TXR_META_LDWBE, input [`SIG_ADDR_W-1:0] TXR_META_ADDR, input [`SIG_LEN_W-1:0] TXR_META_LENGTH, input [`SIG_TAG_W-1:0] TXR_META_TAG, input [`SIG_TC_W-1:0] TXR_META_TC, input [`SIG_ATTR_W-1:0] TXR_META_ATTR, input [`SIG_TYPE_W-1:0] TXR_META_TYPE, input TXR_META_EP, output TXR_META_READY, output TXR_SENT); wire CLK; assign CLK = CLK_BUS; generate /* verilator lint_off WIDTH */ if(C_VENDOR != "ULTRASCALE") begin assign M_AXIS_CQ_TREADY = 0; assign M_AXIS_RC_TREADY = 0; assign S_AXIS_CC_TVALID = 0; assign S_AXIS_CC_TLAST = 0; assign S_AXIS_CC_TDATA = 0; assign S_AXIS_CC_TKEEP = 0; assign S_AXIS_CC_TUSER = 0; assign S_AXIS_RQ_TVALID = 0; assign S_AXIS_RQ_TLAST = 0; assign S_AXIS_RQ_TDATA = 0; assign S_AXIS_RQ_TKEEP = 0; assign S_AXIS_RQ_TUSER = 0; /* verilator lint_on WIDTH */ rx_engine_classic #(/*AUTOINSTPARAM*/ // Parameters .C_VENDOR (C_VENDOR), .C_PCI_DATA_WIDTH (C_PCI_DATA_WIDTH), .C_LOG_NUM_TAGS (C_LOG_NUM_TAGS)) rx_engine_classic_inst (/*AUTOINST*/ // Outputs .DONE_RXR_RST (DONE_RXR_RST), .DONE_RXC_RST (DONE_RXC_RST), .RX_TLP_READY (RX_TLP_READY), .RXC_DATA (RXC_DATA[C_PCI_DATA_WIDTH-1:0]), .RXC_DATA_VALID (RXC_DATA_VALID), .RXC_DATA_WORD_ENABLE (RXC_DATA_WORD_ENABLE[(C_PCI_DATA_WIDTH/32)-1:0]), .RXC_DATA_START_FLAG (RXC_DATA_START_FLAG), .RXC_DATA_START_OFFSET (RXC_DATA_START_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .RXC_DATA_END_FLAG (RXC_DATA_END_FLAG), .RXC_DATA_END_OFFSET (RXC_DATA_END_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .RXC_META_LDWBE (RXC_META_LDWBE[`SIG_LBE_W-1:0]), .RXC_META_FDWBE (RXC_META_FDWBE[`SIG_FBE_W-1:0]), .RXC_META_TAG (RXC_META_TAG[`SIG_TAG_W-1:0]), .RXC_META_ADDR (RXC_META_ADDR[`SIG_LOWADDR_W-1:0]), .RXC_META_TYPE (RXC_META_TYPE[`SIG_TYPE_W-1:0]), .RXC_META_LENGTH (RXC_META_LENGTH[`SIG_LEN_W-1:0]), .RXC_META_BYTES_REMAINING(RXC_META_BYTES_REMAINING[`SIG_BYTECNT_W-1:0]), .RXC_META_COMPLETER_ID (RXC_META_COMPLETER_ID[`SIG_CPLID_W-1:0]), .RXC_META_EP (RXC_META_EP), .RXR_DATA (RXR_DATA[C_PCI_DATA_WIDTH-1:0]), .RXR_DATA_VALID (RXR_DATA_VALID), .RXR_DATA_WORD_ENABLE (RXR_DATA_WORD_ENABLE[(C_PCI_DATA_WIDTH/32)-1:0]), .RXR_DATA_START_FLAG (RXR_DATA_START_FLAG), .RXR_DATA_START_OFFSET (RXR_DATA_START_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .RXR_DATA_END_FLAG (RXR_DATA_END_FLAG), .RXR_DATA_END_OFFSET (RXR_DATA_END_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .RXR_META_FDWBE (RXR_META_FDWBE[`SIG_FBE_W-1:0]), .RXR_META_LDWBE (RXR_META_LDWBE[`SIG_LBE_W-1:0]), .RXR_META_TC (RXR_META_TC[`SIG_TC_W-1:0]), .RXR_META_ATTR (RXR_META_ATTR[`SIG_ATTR_W-1:0]), .RXR_META_TAG (RXR_META_TAG[`SIG_TAG_W-1:0]), .RXR_META_TYPE (RXR_META_TYPE[`SIG_TYPE_W-1:0]), .RXR_META_ADDR (RXR_META_ADDR[`SIG_ADDR_W-1:0]), .RXR_META_BAR_DECODED (RXR_META_BAR_DECODED[`SIG_BARDECODE_W-1:0]), .RXR_META_REQUESTER_ID (RXR_META_REQUESTER_ID[`SIG_REQID_W-1:0]), .RXR_META_LENGTH (RXR_META_LENGTH[`SIG_LEN_W-1:0]), .RXR_META_EP (RXR_META_EP), // Inputs .CLK (CLK), .RST_BUS (RST_BUS), .RST_LOGIC (RST_LOGIC), .RX_TLP (RX_TLP[C_PCI_DATA_WIDTH-1:0]), .RX_TLP_VALID (RX_TLP_VALID), .RX_TLP_START_FLAG (RX_TLP_START_FLAG), .RX_TLP_START_OFFSET (RX_TLP_START_OFFSET[`SIG_OFFSET_W-1:0]), .RX_TLP_END_FLAG (RX_TLP_END_FLAG), .RX_TLP_END_OFFSET (RX_TLP_END_OFFSET[`SIG_OFFSET_W-1:0]), .RX_TLP_BAR_DECODE (RX_TLP_BAR_DECODE[`SIG_BARDECODE_W-1:0])); tx_engine_classic #(/*AUTOINSTPARAM*/ // Parameters .C_PCI_DATA_WIDTH (C_PCI_DATA_WIDTH), .C_PIPELINE_INPUT (C_PIPELINE_INPUT), .C_PIPELINE_OUTPUT (C_PIPELINE_OUTPUT), .C_MAX_PAYLOAD_DWORDS (C_MAX_PAYLOAD_DWORDS), .C_VENDOR (C_VENDOR)) tx_engine_classic_inst (/*AUTOINST*/ // Outputs .DONE_TXC_RST (DONE_TXC_RST), .DONE_TXR_RST (DONE_TXR_RST), .TX_TLP (TX_TLP[C_PCI_DATA_WIDTH-1:0]), .TX_TLP_VALID (TX_TLP_VALID), .TX_TLP_START_FLAG (TX_TLP_START_FLAG), .TX_TLP_START_OFFSET (TX_TLP_START_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .TX_TLP_END_FLAG (TX_TLP_END_FLAG), .TX_TLP_END_OFFSET (TX_TLP_END_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .TXC_DATA_READY (TXC_DATA_READY), .TXC_META_READY (TXC_META_READY), .TXC_SENT (TXC_SENT), .TXR_DATA_READY (TXR_DATA_READY), .TXR_META_READY (TXR_META_READY), .TXR_SENT (TXR_SENT), // Inputs .CLK (CLK), .RST_BUS (RST_BUS), .RST_LOGIC (RST_LOGIC), .CONFIG_COMPLETER_ID (CONFIG_COMPLETER_ID[`SIG_CPLID_W-1:0]), .TX_TLP_READY (TX_TLP_READY), .TXC_DATA_VALID (TXC_DATA_VALID), .TXC_DATA (TXC_DATA[C_PCI_DATA_WIDTH-1:0]), .TXC_DATA_START_FLAG (TXC_DATA_START_FLAG), .TXC_DATA_START_OFFSET (TXC_DATA_START_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .TXC_DATA_END_FLAG (TXC_DATA_END_FLAG), .TXC_DATA_END_OFFSET (TXC_DATA_END_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .TXC_META_VALID (TXC_META_VALID), .TXC_META_FDWBE (TXC_META_FDWBE[`SIG_FBE_W-1:0]), .TXC_META_LDWBE (TXC_META_LDWBE[`SIG_LBE_W-1:0]), .TXC_META_ADDR (TXC_META_ADDR[`SIG_LOWADDR_W-1:0]), .TXC_META_TYPE (TXC_META_TYPE[`SIG_TYPE_W-1:0]), .TXC_META_LENGTH (TXC_META_LENGTH[`SIG_LEN_W-1:0]), .TXC_META_BYTE_COUNT (TXC_META_BYTE_COUNT[`SIG_BYTECNT_W-1:0]), .TXC_META_TAG (TXC_META_TAG[`SIG_TAG_W-1:0]), .TXC_META_REQUESTER_ID (TXC_META_REQUESTER_ID[`SIG_REQID_W-1:0]), .TXC_META_TC (TXC_META_TC[`SIG_TC_W-1:0]), .TXC_META_ATTR (TXC_META_ATTR[`SIG_ATTR_W-1:0]), .TXC_META_EP (TXC_META_EP), .TXR_DATA_VALID (TXR_DATA_VALID), .TXR_DATA (TXR_DATA[C_PCI_DATA_WIDTH-1:0]), .TXR_DATA_START_FLAG (TXR_DATA_START_FLAG), .TXR_DATA_START_OFFSET (TXR_DATA_START_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .TXR_DATA_END_FLAG (TXR_DATA_END_FLAG), .TXR_DATA_END_OFFSET (TXR_DATA_END_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .TXR_META_VALID (TXR_META_VALID), .TXR_META_FDWBE (TXR_META_FDWBE[`SIG_FBE_W-1:0]), .TXR_META_LDWBE (TXR_META_LDWBE[`SIG_LBE_W-1:0]), .TXR_META_ADDR (TXR_META_ADDR[`SIG_ADDR_W-1:0]), .TXR_META_LENGTH (TXR_META_LENGTH[`SIG_LEN_W-1:0]), .TXR_META_TAG (TXR_META_TAG[`SIG_TAG_W-1:0]), .TXR_META_TC (TXR_META_TC[`SIG_TC_W-1:0]), .TXR_META_ATTR (TXR_META_ATTR[`SIG_ATTR_W-1:0]), .TXR_META_TYPE (TXR_META_TYPE[`SIG_TYPE_W-1:0]), .TXR_META_EP (TXR_META_EP)); end else begin assign TX_TLP = 0; assign TX_TLP_VALID = 0; assign TX_TLP_START_FLAG = 0; assign TX_TLP_START_OFFSET = 0; assign TX_TLP_END_FLAG = 0; assign TX_TLP_END_OFFSET = 0; assign RX_TLP_READY = 0; rx_engine_ultrascale #(/*AUTOINSTPARAM*/ // Parameters .C_PCI_DATA_WIDTH (C_PCI_DATA_WIDTH)) rx_engine_ultrascale_inst (/*AUTOINST*/ // Outputs .DONE_RXR_RST (DONE_RXR_RST), .DONE_RXC_RST (DONE_RXC_RST), .M_AXIS_CQ_TREADY (M_AXIS_CQ_TREADY), .M_AXIS_RC_TREADY (M_AXIS_RC_TREADY), .RXC_DATA (RXC_DATA[C_PCI_DATA_WIDTH-1:0]), .RXC_DATA_VALID (RXC_DATA_VALID), .RXC_DATA_WORD_ENABLE (RXC_DATA_WORD_ENABLE[(C_PCI_DATA_WIDTH/32)-1:0]), .RXC_DATA_START_FLAG (RXC_DATA_START_FLAG), .RXC_DATA_START_OFFSET (RXC_DATA_START_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .RXC_DATA_END_FLAG (RXC_DATA_END_FLAG), .RXC_DATA_END_OFFSET (RXC_DATA_END_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .RXC_META_LDWBE (RXC_META_LDWBE[`SIG_LBE_W-1:0]), .RXC_META_FDWBE (RXC_META_FDWBE[`SIG_FBE_W-1:0]), .RXC_META_TAG (RXC_META_TAG[`SIG_TAG_W-1:0]), .RXC_META_ADDR (RXC_META_ADDR[`SIG_LOWADDR_W-1:0]), .RXC_META_TYPE (RXC_META_TYPE[`SIG_TYPE_W-1:0]), .RXC_META_LENGTH (RXC_META_LENGTH[`SIG_LEN_W-1:0]), .RXC_META_BYTES_REMAINING(RXC_META_BYTES_REMAINING[`SIG_BYTECNT_W-1:0]), .RXC_META_COMPLETER_ID (RXC_META_COMPLETER_ID[`SIG_CPLID_W-1:0]), .RXC_META_EP (RXC_META_EP), .RXR_DATA (RXR_DATA[C_PCI_DATA_WIDTH-1:0]), .RXR_DATA_VALID (RXR_DATA_VALID), .RXR_DATA_WORD_ENABLE (RXR_DATA_WORD_ENABLE[(C_PCI_DATA_WIDTH/32)-1:0]), .RXR_DATA_START_FLAG (RXR_DATA_START_FLAG), .RXR_DATA_START_OFFSET (RXR_DATA_START_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .RXR_DATA_END_FLAG (RXR_DATA_END_FLAG), .RXR_DATA_END_OFFSET (RXR_DATA_END_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .RXR_META_FDWBE (RXR_META_FDWBE[`SIG_FBE_W-1:0]), .RXR_META_LDWBE (RXR_META_LDWBE[`SIG_LBE_W-1:0]), .RXR_META_TC (RXR_META_TC[`SIG_TC_W-1:0]), .RXR_META_ATTR (RXR_META_ATTR[`SIG_ATTR_W-1:0]), .RXR_META_TAG (RXR_META_TAG[`SIG_TAG_W-1:0]), .RXR_META_TYPE (RXR_META_TYPE[`SIG_TYPE_W-1:0]), .RXR_META_ADDR (RXR_META_ADDR[`SIG_ADDR_W-1:0]), .RXR_META_BAR_DECODED (RXR_META_BAR_DECODED[`SIG_BARDECODE_W-1:0]), .RXR_META_REQUESTER_ID (RXR_META_REQUESTER_ID[`SIG_REQID_W-1:0]), .RXR_META_LENGTH (RXR_META_LENGTH[`SIG_LEN_W-1:0]), .RXR_META_EP (RXR_META_EP), // Inputs .CLK (CLK), .RST_BUS (RST_BUS), .RST_LOGIC (RST_LOGIC), .M_AXIS_CQ_TVALID (M_AXIS_CQ_TVALID), .M_AXIS_CQ_TLAST (M_AXIS_CQ_TLAST), .M_AXIS_CQ_TDATA (M_AXIS_CQ_TDATA[C_PCI_DATA_WIDTH-1:0]), .M_AXIS_CQ_TKEEP (M_AXIS_CQ_TKEEP[(C_PCI_DATA_WIDTH/32)-1:0]), .M_AXIS_CQ_TUSER (M_AXIS_CQ_TUSER[`SIG_CQ_TUSER_W-1:0]), .M_AXIS_RC_TVALID (M_AXIS_RC_TVALID), .M_AXIS_RC_TLAST (M_AXIS_RC_TLAST), .M_AXIS_RC_TDATA (M_AXIS_RC_TDATA[C_PCI_DATA_WIDTH-1:0]), .M_AXIS_RC_TKEEP (M_AXIS_RC_TKEEP[(C_PCI_DATA_WIDTH/32)-1:0]), .M_AXIS_RC_TUSER (M_AXIS_RC_TUSER[`SIG_RC_TUSER_W-1:0])); tx_engine_ultrascale #(/*AUTOINSTPARAM*/ // Parameters .C_PCI_DATA_WIDTH (C_PCI_DATA_WIDTH), .C_PIPELINE_INPUT (C_PIPELINE_INPUT), .C_PIPELINE_OUTPUT (C_PIPELINE_OUTPUT), .C_MAX_PAYLOAD_DWORDS (C_MAX_PAYLOAD_DWORDS)) tx_engine_ultrascale_inst (/*AUTOINST*/ // Outputs .DONE_TXC_RST (DONE_TXC_RST), .DONE_TXR_RST (DONE_TXR_RST), .S_AXIS_CC_TVALID (S_AXIS_CC_TVALID), .S_AXIS_CC_TLAST (S_AXIS_CC_TLAST), .S_AXIS_CC_TDATA (S_AXIS_CC_TDATA[C_PCI_DATA_WIDTH-1:0]), .S_AXIS_CC_TKEEP (S_AXIS_CC_TKEEP[(C_PCI_DATA_WIDTH/32)-1:0]), .S_AXIS_CC_TUSER (S_AXIS_CC_TUSER[`SIG_CC_TUSER_W-1:0]), .TXC_DATA_READY (TXC_DATA_READY), .TXC_META_READY (TXC_META_READY), .TXC_SENT (TXC_SENT), .S_AXIS_RQ_TVALID (S_AXIS_RQ_TVALID), .S_AXIS_RQ_TLAST (S_AXIS_RQ_TLAST), .S_AXIS_RQ_TDATA (S_AXIS_RQ_TDATA[C_PCI_DATA_WIDTH-1:0]), .S_AXIS_RQ_TKEEP (S_AXIS_RQ_TKEEP[(C_PCI_DATA_WIDTH/32)-1:0]), .S_AXIS_RQ_TUSER (S_AXIS_RQ_TUSER[`SIG_RQ_TUSER_W-1:0]), .TXR_DATA_READY (TXR_DATA_READY), .TXR_META_READY (TXR_META_READY), .TXR_SENT (TXR_SENT), // Inputs .CLK (CLK), .RST_BUS (RST_BUS), .RST_LOGIC (RST_LOGIC), .CONFIG_COMPLETER_ID (CONFIG_COMPLETER_ID[`SIG_CPLID_W-1:0]), .S_AXIS_CC_TREADY (S_AXIS_CC_TREADY), .TXC_DATA_VALID (TXC_DATA_VALID), .TXC_DATA (TXC_DATA[C_PCI_DATA_WIDTH-1:0]), .TXC_DATA_START_FLAG (TXC_DATA_START_FLAG), .TXC_DATA_START_OFFSET (TXC_DATA_START_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .TXC_DATA_END_FLAG (TXC_DATA_END_FLAG), .TXC_DATA_END_OFFSET (TXC_DATA_END_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .TXC_META_VALID (TXC_META_VALID), .TXC_META_FDWBE (TXC_META_FDWBE[`SIG_FBE_W-1:0]), .TXC_META_LDWBE (TXC_META_LDWBE[`SIG_LBE_W-1:0]), .TXC_META_ADDR (TXC_META_ADDR[`SIG_LOWADDR_W-1:0]), .TXC_META_TYPE (TXC_META_TYPE[`SIG_TYPE_W-1:0]), .TXC_META_LENGTH (TXC_META_LENGTH[`SIG_LEN_W-1:0]), .TXC_META_BYTE_COUNT (TXC_META_BYTE_COUNT[`SIG_BYTECNT_W-1:0]), .TXC_META_TAG (TXC_META_TAG[`SIG_TAG_W-1:0]), .TXC_META_REQUESTER_ID (TXC_META_REQUESTER_ID[`SIG_REQID_W-1:0]), .TXC_META_TC (TXC_META_TC[`SIG_TC_W-1:0]), .TXC_META_ATTR (TXC_META_ATTR[`SIG_ATTR_W-1:0]), .TXC_META_EP (TXC_META_EP), .S_AXIS_RQ_TREADY (S_AXIS_RQ_TREADY), .TXR_DATA_VALID (TXR_DATA_VALID), .TXR_DATA (TXR_DATA[C_PCI_DATA_WIDTH-1:0]), .TXR_DATA_START_FLAG (TXR_DATA_START_FLAG), .TXR_DATA_START_OFFSET (TXR_DATA_START_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .TXR_DATA_END_FLAG (TXR_DATA_END_FLAG), .TXR_DATA_END_OFFSET (TXR_DATA_END_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .TXR_META_VALID (TXR_META_VALID), .TXR_META_FDWBE (TXR_META_FDWBE[`SIG_FBE_W-1:0]), .TXR_META_LDWBE (TXR_META_LDWBE[`SIG_LBE_W-1:0]), .TXR_META_ADDR (TXR_META_ADDR[`SIG_ADDR_W-1:0]), .TXR_META_LENGTH (TXR_META_LENGTH[`SIG_LEN_W-1:0]), .TXR_META_TAG (TXR_META_TAG[`SIG_TAG_W-1:0]), .TXR_META_TC (TXR_META_TC[`SIG_TC_W-1:0]), .TXR_META_ATTR (TXR_META_ATTR[`SIG_ATTR_W-1:0]), .TXR_META_TYPE (TXR_META_TYPE[`SIG_TYPE_W-1:0]), .TXR_META_EP (TXR_META_EP)); end endgenerate endmodule // engine_layer // Local Variables: // verilog-library-directories:("." "ultrascale/rx/" "ultrascale/tx/" "classic/rx/" "classic/tx/") // End:
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * 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. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // 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 REGENTS OF THE // UNIVERSITY OF CALIFORNIA 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. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: engine_layer.v // Version: 1.0 // Verilog Standard: Verilog-2001 // Description: The engine layer encapsulates the RX and TX engines. // Author: Dustin Richmond (@darichmond) //----------------------------------------------------------------------------- `timescale 1ns/1ns `include "trellis.vh" `include "ultrascale.vh" module engine_layer #(parameter C_PCI_DATA_WIDTH = 128, parameter C_LOG_NUM_TAGS=6, parameter C_PIPELINE_INPUT = 1, parameter C_PIPELINE_OUTPUT = 0, parameter C_MAX_PAYLOAD_DWORDS = 64, parameter C_VENDOR="ULTRASCALE") (// Interface: Clocks input CLK_BUS, // Replacement for generic CLK // Interface: Resets input RST_BUS, // Replacement for generic RST_IN input RST_LOGIC, // Addition for RIFFA_RST output DONE_TXC_RST, output DONE_TXR_RST, output DONE_RXR_RST, output DONE_RXC_RST, // Interface: Configuration input [`SIG_CPLID_W-1:0] CONFIG_COMPLETER_ID, // Interface: RX Classic input [C_PCI_DATA_WIDTH-1:0] RX_TLP, input RX_TLP_VALID, input RX_TLP_START_FLAG, input [`SIG_OFFSET_W-1:0] RX_TLP_START_OFFSET, input RX_TLP_END_FLAG, input [`SIG_OFFSET_W-1:0] RX_TLP_END_OFFSET, input [`SIG_BARDECODE_W-1:0] RX_TLP_BAR_DECODE, output RX_TLP_READY, // Interface: TX Classic input TX_TLP_READY, output [C_PCI_DATA_WIDTH-1:0] TX_TLP, output TX_TLP_VALID, output TX_TLP_START_FLAG, output [`SIG_OFFSET_W-1:0] TX_TLP_START_OFFSET, output TX_TLP_END_FLAG, output [`SIG_OFFSET_W-1:0] TX_TLP_END_OFFSET, //Interface: CQ Ultrascale (RXR) input M_AXIS_CQ_TVALID, input M_AXIS_CQ_TLAST, input [C_PCI_DATA_WIDTH-1:0] M_AXIS_CQ_TDATA, input [(C_PCI_DATA_WIDTH/32)-1:0] M_AXIS_CQ_TKEEP, input [`SIG_CQ_TUSER_W-1:0] M_AXIS_CQ_TUSER, output M_AXIS_CQ_TREADY, //Interface: RC Ultrascale (RXC) input M_AXIS_RC_TVALID, input M_AXIS_RC_TLAST, input [C_PCI_DATA_WIDTH-1:0] M_AXIS_RC_TDATA, input [(C_PCI_DATA_WIDTH/32)-1:0] M_AXIS_RC_TKEEP, input [`SIG_RC_TUSER_W-1:0] M_AXIS_RC_TUSER, output M_AXIS_RC_TREADY, //Interface: CC Ultrascale (TXC) input S_AXIS_CC_TREADY, output S_AXIS_CC_TVALID, output S_AXIS_CC_TLAST, output [C_PCI_DATA_WIDTH-1:0] S_AXIS_CC_TDATA, output [(C_PCI_DATA_WIDTH/32)-1:0] S_AXIS_CC_TKEEP, output [`SIG_CC_TUSER_W-1:0] S_AXIS_CC_TUSER, //Interface: RQ Ultrascale (TXR) input S_AXIS_RQ_TREADY, output S_AXIS_RQ_TVALID, output S_AXIS_RQ_TLAST, output [C_PCI_DATA_WIDTH-1:0] S_AXIS_RQ_TDATA, output [(C_PCI_DATA_WIDTH/32)-1:0] S_AXIS_RQ_TKEEP, output [`SIG_RQ_TUSER_W-1:0] S_AXIS_RQ_TUSER, // Interface: RXC Engine output [C_PCI_DATA_WIDTH-1:0] RXC_DATA, output RXC_DATA_VALID, output [(C_PCI_DATA_WIDTH/32)-1:0] RXC_DATA_WORD_ENABLE, output RXC_DATA_START_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] RXC_DATA_START_OFFSET, output RXC_DATA_END_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] RXC_DATA_END_OFFSET, output [`SIG_LBE_W-1:0] RXC_META_LDWBE, output [`SIG_FBE_W-1:0] RXC_META_FDWBE, output [`SIG_TAG_W-1:0] RXC_META_TAG, output [`SIG_LOWADDR_W-1:0] RXC_META_ADDR, output [`SIG_TYPE_W-1:0] RXC_META_TYPE, output [`SIG_LEN_W-1:0] RXC_META_LENGTH, output [`SIG_BYTECNT_W-1:0] RXC_META_BYTES_REMAINING, output [`SIG_CPLID_W-1:0] RXC_META_COMPLETER_ID, output RXC_META_EP, // Interface: RXR Engine output [C_PCI_DATA_WIDTH-1:0] RXR_DATA, output RXR_DATA_VALID, output [(C_PCI_DATA_WIDTH/32)-1:0] RXR_DATA_WORD_ENABLE, output RXR_DATA_START_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] RXR_DATA_START_OFFSET, output RXR_DATA_END_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] RXR_DATA_END_OFFSET, output [`SIG_FBE_W-1:0] RXR_META_FDWBE, output [`SIG_LBE_W-1:0] RXR_META_LDWBE, output [`SIG_TC_W-1:0] RXR_META_TC, output [`SIG_ATTR_W-1:0] RXR_META_ATTR, output [`SIG_TAG_W-1:0] RXR_META_TAG, output [`SIG_TYPE_W-1:0] RXR_META_TYPE, output [`SIG_ADDR_W-1:0] RXR_META_ADDR, output [`SIG_BARDECODE_W-1:0] RXR_META_BAR_DECODED, output [`SIG_REQID_W-1:0] RXR_META_REQUESTER_ID, output [`SIG_LEN_W-1:0] RXR_META_LENGTH, output RXR_META_EP, // Interface: TXC Engine input TXC_DATA_VALID, input [C_PCI_DATA_WIDTH-1:0] TXC_DATA, input TXC_DATA_START_FLAG, input [clog2s(C_PCI_DATA_WIDTH/32)-1:0] TXC_DATA_START_OFFSET, input TXC_DATA_END_FLAG, input [clog2s(C_PCI_DATA_WIDTH/32)-1:0] TXC_DATA_END_OFFSET, output TXC_DATA_READY, input TXC_META_VALID, input [`SIG_FBE_W-1:0] TXC_META_FDWBE, input [`SIG_LBE_W-1:0] TXC_META_LDWBE, input [`SIG_LOWADDR_W-1:0] TXC_META_ADDR, input [`SIG_TYPE_W-1:0] TXC_META_TYPE, input [`SIG_LEN_W-1:0] TXC_META_LENGTH, input [`SIG_BYTECNT_W-1:0] TXC_META_BYTE_COUNT, input [`SIG_TAG_W-1:0] TXC_META_TAG, input [`SIG_REQID_W-1:0] TXC_META_REQUESTER_ID, input [`SIG_TC_W-1:0] TXC_META_TC, input [`SIG_ATTR_W-1:0] TXC_META_ATTR, input TXC_META_EP, output TXC_META_READY, output TXC_SENT, // Interface: TXR Engine input TXR_DATA_VALID, input [C_PCI_DATA_WIDTH-1:0] TXR_DATA, input TXR_DATA_START_FLAG, input [clog2s(C_PCI_DATA_WIDTH/32)-1:0] TXR_DATA_START_OFFSET, input TXR_DATA_END_FLAG, input [clog2s(C_PCI_DATA_WIDTH/32)-1:0] TXR_DATA_END_OFFSET, output TXR_DATA_READY, input TXR_META_VALID, input [`SIG_FBE_W-1:0] TXR_META_FDWBE, input [`SIG_LBE_W-1:0] TXR_META_LDWBE, input [`SIG_ADDR_W-1:0] TXR_META_ADDR, input [`SIG_LEN_W-1:0] TXR_META_LENGTH, input [`SIG_TAG_W-1:0] TXR_META_TAG, input [`SIG_TC_W-1:0] TXR_META_TC, input [`SIG_ATTR_W-1:0] TXR_META_ATTR, input [`SIG_TYPE_W-1:0] TXR_META_TYPE, input TXR_META_EP, output TXR_META_READY, output TXR_SENT); wire CLK; assign CLK = CLK_BUS; generate /* verilator lint_off WIDTH */ if(C_VENDOR != "ULTRASCALE") begin assign M_AXIS_CQ_TREADY = 0; assign M_AXIS_RC_TREADY = 0; assign S_AXIS_CC_TVALID = 0; assign S_AXIS_CC_TLAST = 0; assign S_AXIS_CC_TDATA = 0; assign S_AXIS_CC_TKEEP = 0; assign S_AXIS_CC_TUSER = 0; assign S_AXIS_RQ_TVALID = 0; assign S_AXIS_RQ_TLAST = 0; assign S_AXIS_RQ_TDATA = 0; assign S_AXIS_RQ_TKEEP = 0; assign S_AXIS_RQ_TUSER = 0; /* verilator lint_on WIDTH */ rx_engine_classic #(/*AUTOINSTPARAM*/ // Parameters .C_VENDOR (C_VENDOR), .C_PCI_DATA_WIDTH (C_PCI_DATA_WIDTH), .C_LOG_NUM_TAGS (C_LOG_NUM_TAGS)) rx_engine_classic_inst (/*AUTOINST*/ // Outputs .DONE_RXR_RST (DONE_RXR_RST), .DONE_RXC_RST (DONE_RXC_RST), .RX_TLP_READY (RX_TLP_READY), .RXC_DATA (RXC_DATA[C_PCI_DATA_WIDTH-1:0]), .RXC_DATA_VALID (RXC_DATA_VALID), .RXC_DATA_WORD_ENABLE (RXC_DATA_WORD_ENABLE[(C_PCI_DATA_WIDTH/32)-1:0]), .RXC_DATA_START_FLAG (RXC_DATA_START_FLAG), .RXC_DATA_START_OFFSET (RXC_DATA_START_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .RXC_DATA_END_FLAG (RXC_DATA_END_FLAG), .RXC_DATA_END_OFFSET (RXC_DATA_END_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .RXC_META_LDWBE (RXC_META_LDWBE[`SIG_LBE_W-1:0]), .RXC_META_FDWBE (RXC_META_FDWBE[`SIG_FBE_W-1:0]), .RXC_META_TAG (RXC_META_TAG[`SIG_TAG_W-1:0]), .RXC_META_ADDR (RXC_META_ADDR[`SIG_LOWADDR_W-1:0]), .RXC_META_TYPE (RXC_META_TYPE[`SIG_TYPE_W-1:0]), .RXC_META_LENGTH (RXC_META_LENGTH[`SIG_LEN_W-1:0]), .RXC_META_BYTES_REMAINING(RXC_META_BYTES_REMAINING[`SIG_BYTECNT_W-1:0]), .RXC_META_COMPLETER_ID (RXC_META_COMPLETER_ID[`SIG_CPLID_W-1:0]), .RXC_META_EP (RXC_META_EP), .RXR_DATA (RXR_DATA[C_PCI_DATA_WIDTH-1:0]), .RXR_DATA_VALID (RXR_DATA_VALID), .RXR_DATA_WORD_ENABLE (RXR_DATA_WORD_ENABLE[(C_PCI_DATA_WIDTH/32)-1:0]), .RXR_DATA_START_FLAG (RXR_DATA_START_FLAG), .RXR_DATA_START_OFFSET (RXR_DATA_START_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .RXR_DATA_END_FLAG (RXR_DATA_END_FLAG), .RXR_DATA_END_OFFSET (RXR_DATA_END_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .RXR_META_FDWBE (RXR_META_FDWBE[`SIG_FBE_W-1:0]), .RXR_META_LDWBE (RXR_META_LDWBE[`SIG_LBE_W-1:0]), .RXR_META_TC (RXR_META_TC[`SIG_TC_W-1:0]), .RXR_META_ATTR (RXR_META_ATTR[`SIG_ATTR_W-1:0]), .RXR_META_TAG (RXR_META_TAG[`SIG_TAG_W-1:0]), .RXR_META_TYPE (RXR_META_TYPE[`SIG_TYPE_W-1:0]), .RXR_META_ADDR (RXR_META_ADDR[`SIG_ADDR_W-1:0]), .RXR_META_BAR_DECODED (RXR_META_BAR_DECODED[`SIG_BARDECODE_W-1:0]), .RXR_META_REQUESTER_ID (RXR_META_REQUESTER_ID[`SIG_REQID_W-1:0]), .RXR_META_LENGTH (RXR_META_LENGTH[`SIG_LEN_W-1:0]), .RXR_META_EP (RXR_META_EP), // Inputs .CLK (CLK), .RST_BUS (RST_BUS), .RST_LOGIC (RST_LOGIC), .RX_TLP (RX_TLP[C_PCI_DATA_WIDTH-1:0]), .RX_TLP_VALID (RX_TLP_VALID), .RX_TLP_START_FLAG (RX_TLP_START_FLAG), .RX_TLP_START_OFFSET (RX_TLP_START_OFFSET[`SIG_OFFSET_W-1:0]), .RX_TLP_END_FLAG (RX_TLP_END_FLAG), .RX_TLP_END_OFFSET (RX_TLP_END_OFFSET[`SIG_OFFSET_W-1:0]), .RX_TLP_BAR_DECODE (RX_TLP_BAR_DECODE[`SIG_BARDECODE_W-1:0])); tx_engine_classic #(/*AUTOINSTPARAM*/ // Parameters .C_PCI_DATA_WIDTH (C_PCI_DATA_WIDTH), .C_PIPELINE_INPUT (C_PIPELINE_INPUT), .C_PIPELINE_OUTPUT (C_PIPELINE_OUTPUT), .C_MAX_PAYLOAD_DWORDS (C_MAX_PAYLOAD_DWORDS), .C_VENDOR (C_VENDOR)) tx_engine_classic_inst (/*AUTOINST*/ // Outputs .DONE_TXC_RST (DONE_TXC_RST), .DONE_TXR_RST (DONE_TXR_RST), .TX_TLP (TX_TLP[C_PCI_DATA_WIDTH-1:0]), .TX_TLP_VALID (TX_TLP_VALID), .TX_TLP_START_FLAG (TX_TLP_START_FLAG), .TX_TLP_START_OFFSET (TX_TLP_START_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .TX_TLP_END_FLAG (TX_TLP_END_FLAG), .TX_TLP_END_OFFSET (TX_TLP_END_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .TXC_DATA_READY (TXC_DATA_READY), .TXC_META_READY (TXC_META_READY), .TXC_SENT (TXC_SENT), .TXR_DATA_READY (TXR_DATA_READY), .TXR_META_READY (TXR_META_READY), .TXR_SENT (TXR_SENT), // Inputs .CLK (CLK), .RST_BUS (RST_BUS), .RST_LOGIC (RST_LOGIC), .CONFIG_COMPLETER_ID (CONFIG_COMPLETER_ID[`SIG_CPLID_W-1:0]), .TX_TLP_READY (TX_TLP_READY), .TXC_DATA_VALID (TXC_DATA_VALID), .TXC_DATA (TXC_DATA[C_PCI_DATA_WIDTH-1:0]), .TXC_DATA_START_FLAG (TXC_DATA_START_FLAG), .TXC_DATA_START_OFFSET (TXC_DATA_START_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .TXC_DATA_END_FLAG (TXC_DATA_END_FLAG), .TXC_DATA_END_OFFSET (TXC_DATA_END_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .TXC_META_VALID (TXC_META_VALID), .TXC_META_FDWBE (TXC_META_FDWBE[`SIG_FBE_W-1:0]), .TXC_META_LDWBE (TXC_META_LDWBE[`SIG_LBE_W-1:0]), .TXC_META_ADDR (TXC_META_ADDR[`SIG_LOWADDR_W-1:0]), .TXC_META_TYPE (TXC_META_TYPE[`SIG_TYPE_W-1:0]), .TXC_META_LENGTH (TXC_META_LENGTH[`SIG_LEN_W-1:0]), .TXC_META_BYTE_COUNT (TXC_META_BYTE_COUNT[`SIG_BYTECNT_W-1:0]), .TXC_META_TAG (TXC_META_TAG[`SIG_TAG_W-1:0]), .TXC_META_REQUESTER_ID (TXC_META_REQUESTER_ID[`SIG_REQID_W-1:0]), .TXC_META_TC (TXC_META_TC[`SIG_TC_W-1:0]), .TXC_META_ATTR (TXC_META_ATTR[`SIG_ATTR_W-1:0]), .TXC_META_EP (TXC_META_EP), .TXR_DATA_VALID (TXR_DATA_VALID), .TXR_DATA (TXR_DATA[C_PCI_DATA_WIDTH-1:0]), .TXR_DATA_START_FLAG (TXR_DATA_START_FLAG), .TXR_DATA_START_OFFSET (TXR_DATA_START_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .TXR_DATA_END_FLAG (TXR_DATA_END_FLAG), .TXR_DATA_END_OFFSET (TXR_DATA_END_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .TXR_META_VALID (TXR_META_VALID), .TXR_META_FDWBE (TXR_META_FDWBE[`SIG_FBE_W-1:0]), .TXR_META_LDWBE (TXR_META_LDWBE[`SIG_LBE_W-1:0]), .TXR_META_ADDR (TXR_META_ADDR[`SIG_ADDR_W-1:0]), .TXR_META_LENGTH (TXR_META_LENGTH[`SIG_LEN_W-1:0]), .TXR_META_TAG (TXR_META_TAG[`SIG_TAG_W-1:0]), .TXR_META_TC (TXR_META_TC[`SIG_TC_W-1:0]), .TXR_META_ATTR (TXR_META_ATTR[`SIG_ATTR_W-1:0]), .TXR_META_TYPE (TXR_META_TYPE[`SIG_TYPE_W-1:0]), .TXR_META_EP (TXR_META_EP)); end else begin assign TX_TLP = 0; assign TX_TLP_VALID = 0; assign TX_TLP_START_FLAG = 0; assign TX_TLP_START_OFFSET = 0; assign TX_TLP_END_FLAG = 0; assign TX_TLP_END_OFFSET = 0; assign RX_TLP_READY = 0; rx_engine_ultrascale #(/*AUTOINSTPARAM*/ // Parameters .C_PCI_DATA_WIDTH (C_PCI_DATA_WIDTH)) rx_engine_ultrascale_inst (/*AUTOINST*/ // Outputs .DONE_RXR_RST (DONE_RXR_RST), .DONE_RXC_RST (DONE_RXC_RST), .M_AXIS_CQ_TREADY (M_AXIS_CQ_TREADY), .M_AXIS_RC_TREADY (M_AXIS_RC_TREADY), .RXC_DATA (RXC_DATA[C_PCI_DATA_WIDTH-1:0]), .RXC_DATA_VALID (RXC_DATA_VALID), .RXC_DATA_WORD_ENABLE (RXC_DATA_WORD_ENABLE[(C_PCI_DATA_WIDTH/32)-1:0]), .RXC_DATA_START_FLAG (RXC_DATA_START_FLAG), .RXC_DATA_START_OFFSET (RXC_DATA_START_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .RXC_DATA_END_FLAG (RXC_DATA_END_FLAG), .RXC_DATA_END_OFFSET (RXC_DATA_END_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .RXC_META_LDWBE (RXC_META_LDWBE[`SIG_LBE_W-1:0]), .RXC_META_FDWBE (RXC_META_FDWBE[`SIG_FBE_W-1:0]), .RXC_META_TAG (RXC_META_TAG[`SIG_TAG_W-1:0]), .RXC_META_ADDR (RXC_META_ADDR[`SIG_LOWADDR_W-1:0]), .RXC_META_TYPE (RXC_META_TYPE[`SIG_TYPE_W-1:0]), .RXC_META_LENGTH (RXC_META_LENGTH[`SIG_LEN_W-1:0]), .RXC_META_BYTES_REMAINING(RXC_META_BYTES_REMAINING[`SIG_BYTECNT_W-1:0]), .RXC_META_COMPLETER_ID (RXC_META_COMPLETER_ID[`SIG_CPLID_W-1:0]), .RXC_META_EP (RXC_META_EP), .RXR_DATA (RXR_DATA[C_PCI_DATA_WIDTH-1:0]), .RXR_DATA_VALID (RXR_DATA_VALID), .RXR_DATA_WORD_ENABLE (RXR_DATA_WORD_ENABLE[(C_PCI_DATA_WIDTH/32)-1:0]), .RXR_DATA_START_FLAG (RXR_DATA_START_FLAG), .RXR_DATA_START_OFFSET (RXR_DATA_START_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .RXR_DATA_END_FLAG (RXR_DATA_END_FLAG), .RXR_DATA_END_OFFSET (RXR_DATA_END_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .RXR_META_FDWBE (RXR_META_FDWBE[`SIG_FBE_W-1:0]), .RXR_META_LDWBE (RXR_META_LDWBE[`SIG_LBE_W-1:0]), .RXR_META_TC (RXR_META_TC[`SIG_TC_W-1:0]), .RXR_META_ATTR (RXR_META_ATTR[`SIG_ATTR_W-1:0]), .RXR_META_TAG (RXR_META_TAG[`SIG_TAG_W-1:0]), .RXR_META_TYPE (RXR_META_TYPE[`SIG_TYPE_W-1:0]), .RXR_META_ADDR (RXR_META_ADDR[`SIG_ADDR_W-1:0]), .RXR_META_BAR_DECODED (RXR_META_BAR_DECODED[`SIG_BARDECODE_W-1:0]), .RXR_META_REQUESTER_ID (RXR_META_REQUESTER_ID[`SIG_REQID_W-1:0]), .RXR_META_LENGTH (RXR_META_LENGTH[`SIG_LEN_W-1:0]), .RXR_META_EP (RXR_META_EP), // Inputs .CLK (CLK), .RST_BUS (RST_BUS), .RST_LOGIC (RST_LOGIC), .M_AXIS_CQ_TVALID (M_AXIS_CQ_TVALID), .M_AXIS_CQ_TLAST (M_AXIS_CQ_TLAST), .M_AXIS_CQ_TDATA (M_AXIS_CQ_TDATA[C_PCI_DATA_WIDTH-1:0]), .M_AXIS_CQ_TKEEP (M_AXIS_CQ_TKEEP[(C_PCI_DATA_WIDTH/32)-1:0]), .M_AXIS_CQ_TUSER (M_AXIS_CQ_TUSER[`SIG_CQ_TUSER_W-1:0]), .M_AXIS_RC_TVALID (M_AXIS_RC_TVALID), .M_AXIS_RC_TLAST (M_AXIS_RC_TLAST), .M_AXIS_RC_TDATA (M_AXIS_RC_TDATA[C_PCI_DATA_WIDTH-1:0]), .M_AXIS_RC_TKEEP (M_AXIS_RC_TKEEP[(C_PCI_DATA_WIDTH/32)-1:0]), .M_AXIS_RC_TUSER (M_AXIS_RC_TUSER[`SIG_RC_TUSER_W-1:0])); tx_engine_ultrascale #(/*AUTOINSTPARAM*/ // Parameters .C_PCI_DATA_WIDTH (C_PCI_DATA_WIDTH), .C_PIPELINE_INPUT (C_PIPELINE_INPUT), .C_PIPELINE_OUTPUT (C_PIPELINE_OUTPUT), .C_MAX_PAYLOAD_DWORDS (C_MAX_PAYLOAD_DWORDS)) tx_engine_ultrascale_inst (/*AUTOINST*/ // Outputs .DONE_TXC_RST (DONE_TXC_RST), .DONE_TXR_RST (DONE_TXR_RST), .S_AXIS_CC_TVALID (S_AXIS_CC_TVALID), .S_AXIS_CC_TLAST (S_AXIS_CC_TLAST), .S_AXIS_CC_TDATA (S_AXIS_CC_TDATA[C_PCI_DATA_WIDTH-1:0]), .S_AXIS_CC_TKEEP (S_AXIS_CC_TKEEP[(C_PCI_DATA_WIDTH/32)-1:0]), .S_AXIS_CC_TUSER (S_AXIS_CC_TUSER[`SIG_CC_TUSER_W-1:0]), .TXC_DATA_READY (TXC_DATA_READY), .TXC_META_READY (TXC_META_READY), .TXC_SENT (TXC_SENT), .S_AXIS_RQ_TVALID (S_AXIS_RQ_TVALID), .S_AXIS_RQ_TLAST (S_AXIS_RQ_TLAST), .S_AXIS_RQ_TDATA (S_AXIS_RQ_TDATA[C_PCI_DATA_WIDTH-1:0]), .S_AXIS_RQ_TKEEP (S_AXIS_RQ_TKEEP[(C_PCI_DATA_WIDTH/32)-1:0]), .S_AXIS_RQ_TUSER (S_AXIS_RQ_TUSER[`SIG_RQ_TUSER_W-1:0]), .TXR_DATA_READY (TXR_DATA_READY), .TXR_META_READY (TXR_META_READY), .TXR_SENT (TXR_SENT), // Inputs .CLK (CLK), .RST_BUS (RST_BUS), .RST_LOGIC (RST_LOGIC), .CONFIG_COMPLETER_ID (CONFIG_COMPLETER_ID[`SIG_CPLID_W-1:0]), .S_AXIS_CC_TREADY (S_AXIS_CC_TREADY), .TXC_DATA_VALID (TXC_DATA_VALID), .TXC_DATA (TXC_DATA[C_PCI_DATA_WIDTH-1:0]), .TXC_DATA_START_FLAG (TXC_DATA_START_FLAG), .TXC_DATA_START_OFFSET (TXC_DATA_START_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .TXC_DATA_END_FLAG (TXC_DATA_END_FLAG), .TXC_DATA_END_OFFSET (TXC_DATA_END_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .TXC_META_VALID (TXC_META_VALID), .TXC_META_FDWBE (TXC_META_FDWBE[`SIG_FBE_W-1:0]), .TXC_META_LDWBE (TXC_META_LDWBE[`SIG_LBE_W-1:0]), .TXC_META_ADDR (TXC_META_ADDR[`SIG_LOWADDR_W-1:0]), .TXC_META_TYPE (TXC_META_TYPE[`SIG_TYPE_W-1:0]), .TXC_META_LENGTH (TXC_META_LENGTH[`SIG_LEN_W-1:0]), .TXC_META_BYTE_COUNT (TXC_META_BYTE_COUNT[`SIG_BYTECNT_W-1:0]), .TXC_META_TAG (TXC_META_TAG[`SIG_TAG_W-1:0]), .TXC_META_REQUESTER_ID (TXC_META_REQUESTER_ID[`SIG_REQID_W-1:0]), .TXC_META_TC (TXC_META_TC[`SIG_TC_W-1:0]), .TXC_META_ATTR (TXC_META_ATTR[`SIG_ATTR_W-1:0]), .TXC_META_EP (TXC_META_EP), .S_AXIS_RQ_TREADY (S_AXIS_RQ_TREADY), .TXR_DATA_VALID (TXR_DATA_VALID), .TXR_DATA (TXR_DATA[C_PCI_DATA_WIDTH-1:0]), .TXR_DATA_START_FLAG (TXR_DATA_START_FLAG), .TXR_DATA_START_OFFSET (TXR_DATA_START_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .TXR_DATA_END_FLAG (TXR_DATA_END_FLAG), .TXR_DATA_END_OFFSET (TXR_DATA_END_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .TXR_META_VALID (TXR_META_VALID), .TXR_META_FDWBE (TXR_META_FDWBE[`SIG_FBE_W-1:0]), .TXR_META_LDWBE (TXR_META_LDWBE[`SIG_LBE_W-1:0]), .TXR_META_ADDR (TXR_META_ADDR[`SIG_ADDR_W-1:0]), .TXR_META_LENGTH (TXR_META_LENGTH[`SIG_LEN_W-1:0]), .TXR_META_TAG (TXR_META_TAG[`SIG_TAG_W-1:0]), .TXR_META_TC (TXR_META_TC[`SIG_TC_W-1:0]), .TXR_META_ATTR (TXR_META_ATTR[`SIG_ATTR_W-1:0]), .TXR_META_TYPE (TXR_META_TYPE[`SIG_TYPE_W-1:0]), .TXR_META_EP (TXR_META_EP)); end endgenerate endmodule // engine_layer // Local Variables: // verilog-library-directories:("." "ultrascale/rx/" "ultrascale/tx/" "classic/rx/" "classic/tx/") // End:
////////////////////////////////////////////////////////////////////////////////// // d_parallel_FFM_gate_GF12.v for Cosmos OpenSSD // Copyright (c) 2015 Hanyang University ENC Lab. // Contributed by Jinwoo Jeong <[email protected]> // Ilyong Jung <[email protected]> // Yong Ho Song <[email protected]> // // This file is part of Cosmos OpenSSD. // // Cosmos OpenSSD 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. // // Cosmos OpenSSD 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 Cosmos OpenSSD; see the file COPYING. // If not, see <http://www.gnu.org/licenses/>. ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// // Company: ENC Lab. <http://enc.hanyang.ac.kr> // Engineer: Jinwoo Jeong <[email protected]> // Ilyong Jung <[email protected]> // // Project Name: Cosmos OpenSSD // Design Name: BCH Page Decoder // Module Name: d_parallel_FFM_gate_GF12 // File Name: d_parallel_FFM_gate_GF12.v // // Version: v2.0.2-GF12tB // // Description: // - parallel Finite Field Multiplier (FFM) module // - 2 polynomial form input, 1 polynomial form output ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// // Revision History: // // * v2.0.2 // - minor modification for releasing // // * v2.0.1 // - re-factoring // // * v2.0.0 // - based on partial multiplication // - fixed GF // // * v1.0.0 // - based on LFSR // - variable GF by parameter setting ////////////////////////////////////////////////////////////////////////////////// `timescale 1ns / 1ps module d_parallel_FFM_gate_GF12 ( input wire [11: 0] i_poly_form_A, // input term A, polynomial form input wire [11: 0] i_poly_form_B, // input term B, polynomial form output wire [11: 0] o_poly_form_result // output term result, polynomial form ); /////////////////////////////////////////////////////////// // CAUTION! CAUTION! CAUTION! CAUTION! CAUTION! CAUTION! // // // // ONLY FOR 12 BIT POLYNOMIAL MULTIPLICATION // // // // CAUTION! CAUTION! CAUTION! CAUTION! CAUTION! CAUTION! // /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// // CAUTION! CAUTION! CAUTION! CAUTION! CAUTION! CAUTION! // // // // PRIMITIVE POLYNOMIAL // // P(X) = X^12 + X^7 + X^4 + X^3 + 1 // // // // CAUTION! CAUTION! CAUTION! CAUTION! CAUTION! CAUTION! // /////////////////////////////////////////////////////////// wire [11: 6] w_p_A1; // partial term A1 wire [ 5: 0] w_p_A0; // partial term A0 wire [11: 6] w_p_B1; // partial term B1 wire [ 5: 0] w_p_B0; // partial term B0 wire [16: 6] w_p_r_A1_B0; // partial multiplication result A1*B0 wire [10: 0] w_p_r_A0_B0; // partial multiplication result A0*B0 wire [22:12] w_p_r_A1_B1; // partial multiplication result A1*B1 wire [16: 6] w_p_r_A0_B1; // partial multiplication result A0*B1 wire [22: 0] w_p_r_sum; // multiplication result assign w_p_A1[11: 6] = i_poly_form_A[11: 6]; assign w_p_A0[ 5: 0] = i_poly_form_A[ 5: 0]; assign w_p_B1[11: 6] = i_poly_form_B[11: 6]; assign w_p_B0[ 5: 0] = i_poly_form_B[ 5: 0]; // multipliers for partial multiplication d_partial_FFM_gate_6b p_mul_A1_B0 ( .i_a(w_p_A1[11: 6]), .i_b(w_p_B0[ 5: 0]), .o_r(w_p_r_A1_B0[16: 6])); d_partial_FFM_gate_6b p_mul_A0_B0 ( .i_a(w_p_A0[ 5: 0]), .i_b(w_p_B0[ 5: 0]), .o_r(w_p_r_A0_B0[10: 0])); d_partial_FFM_gate_6b p_mul_A1_B1 ( .i_a(w_p_A1[11: 6]), .i_b(w_p_B1[11: 6]), .o_r(w_p_r_A1_B1[22:12])); d_partial_FFM_gate_6b p_mul_A0_B1 ( .i_a(w_p_A0[ 5: 0]), .i_b(w_p_B1[11: 6]), .o_r(w_p_r_A0_B1[16: 6])); // sum partial results assign w_p_r_sum[22:17] = w_p_r_A1_B1[22:17]; assign w_p_r_sum[16:12] = w_p_r_A1_B1[16:12] ^ w_p_r_A0_B1[16:12] ^ w_p_r_A1_B0[16:12]; assign w_p_r_sum[11] = w_p_r_A0_B1[11] ^ w_p_r_A1_B0[11]; assign w_p_r_sum[10: 6] = w_p_r_A0_B1[10: 6] ^ w_p_r_A1_B0[10: 6] ^ w_p_r_A0_B0[10: 6]; assign w_p_r_sum[ 5: 0] = w_p_r_A0_B0[ 5: 0]; // reduce high order terms assign o_poly_form_result[11] = w_p_r_sum[11] ^ w_p_r_sum[16] ^ w_p_r_sum[19] ^ w_p_r_sum[20] ^ w_p_r_sum[21]; assign o_poly_form_result[10] = w_p_r_sum[10] ^ w_p_r_sum[15] ^ w_p_r_sum[18] ^ w_p_r_sum[19] ^ w_p_r_sum[20] ^ w_p_r_sum[22]; assign o_poly_form_result[ 9] = w_p_r_sum[ 9] ^ w_p_r_sum[14] ^ w_p_r_sum[17] ^ w_p_r_sum[18] ^ w_p_r_sum[19] ^ w_p_r_sum[21]; assign o_poly_form_result[ 8] = w_p_r_sum[ 8] ^ w_p_r_sum[13] ^ w_p_r_sum[16] ^ w_p_r_sum[17] ^ w_p_r_sum[18] ^ w_p_r_sum[20]; assign o_poly_form_result[ 7] = w_p_r_sum[ 7] ^ w_p_r_sum[12] ^ w_p_r_sum[15] ^ w_p_r_sum[16] ^ w_p_r_sum[17] ^ w_p_r_sum[19] ^ w_p_r_sum[22]; assign o_poly_form_result[ 6] = w_p_r_sum[ 6] ^ w_p_r_sum[14] ^ w_p_r_sum[15] ^ w_p_r_sum[18] ^ w_p_r_sum[19] ^ w_p_r_sum[20] ^ w_p_r_sum[22]; assign o_poly_form_result[ 5] = w_p_r_sum[ 5] ^ w_p_r_sum[13] ^ w_p_r_sum[14] ^ w_p_r_sum[17] ^ w_p_r_sum[18] ^ w_p_r_sum[19] ^ w_p_r_sum[21] ^ w_p_r_sum[22]; assign o_poly_form_result[ 4] = w_p_r_sum[ 4] ^ w_p_r_sum[12] ^ w_p_r_sum[13] ^ w_p_r_sum[16] ^ w_p_r_sum[17] ^ w_p_r_sum[18] ^ w_p_r_sum[20] ^ w_p_r_sum[21]; assign o_poly_form_result[ 3] = w_p_r_sum[ 3] ^ w_p_r_sum[12] ^ w_p_r_sum[15] ^ w_p_r_sum[17] ^ w_p_r_sum[21] ^ w_p_r_sum[22]; assign o_poly_form_result[ 2] = w_p_r_sum[ 2] ^ w_p_r_sum[14] ^ w_p_r_sum[19] ^ w_p_r_sum[22]; assign o_poly_form_result[ 1] = w_p_r_sum[ 1] ^ w_p_r_sum[13] ^ w_p_r_sum[18] ^ w_p_r_sum[21] ^ w_p_r_sum[22]; assign o_poly_form_result[ 0] = w_p_r_sum[ 0] ^ w_p_r_sum[12] ^ w_p_r_sum[17] ^ w_p_r_sum[20] ^ w_p_r_sum[21] ^ w_p_r_sum[22]; endmodule
////////////////////////////////////////////////////////////////////////////////// // d_parallel_FFM_gate_GF12.v for Cosmos OpenSSD // Copyright (c) 2015 Hanyang University ENC Lab. // Contributed by Jinwoo Jeong <[email protected]> // Ilyong Jung <[email protected]> // Yong Ho Song <[email protected]> // // This file is part of Cosmos OpenSSD. // // Cosmos OpenSSD 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. // // Cosmos OpenSSD 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 Cosmos OpenSSD; see the file COPYING. // If not, see <http://www.gnu.org/licenses/>. ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// // Company: ENC Lab. <http://enc.hanyang.ac.kr> // Engineer: Jinwoo Jeong <[email protected]> // Ilyong Jung <[email protected]> // // Project Name: Cosmos OpenSSD // Design Name: BCH Page Decoder // Module Name: d_parallel_FFM_gate_GF12 // File Name: d_parallel_FFM_gate_GF12.v // // Version: v2.0.2-GF12tB // // Description: // - parallel Finite Field Multiplier (FFM) module // - 2 polynomial form input, 1 polynomial form output ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// // Revision History: // // * v2.0.2 // - minor modification for releasing // // * v2.0.1 // - re-factoring // // * v2.0.0 // - based on partial multiplication // - fixed GF // // * v1.0.0 // - based on LFSR // - variable GF by parameter setting ////////////////////////////////////////////////////////////////////////////////// `timescale 1ns / 1ps module d_parallel_FFM_gate_GF12 ( input wire [11: 0] i_poly_form_A, // input term A, polynomial form input wire [11: 0] i_poly_form_B, // input term B, polynomial form output wire [11: 0] o_poly_form_result // output term result, polynomial form ); /////////////////////////////////////////////////////////// // CAUTION! CAUTION! CAUTION! CAUTION! CAUTION! CAUTION! // // // // ONLY FOR 12 BIT POLYNOMIAL MULTIPLICATION // // // // CAUTION! CAUTION! CAUTION! CAUTION! CAUTION! CAUTION! // /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// // CAUTION! CAUTION! CAUTION! CAUTION! CAUTION! CAUTION! // // // // PRIMITIVE POLYNOMIAL // // P(X) = X^12 + X^7 + X^4 + X^3 + 1 // // // // CAUTION! CAUTION! CAUTION! CAUTION! CAUTION! CAUTION! // /////////////////////////////////////////////////////////// wire [11: 6] w_p_A1; // partial term A1 wire [ 5: 0] w_p_A0; // partial term A0 wire [11: 6] w_p_B1; // partial term B1 wire [ 5: 0] w_p_B0; // partial term B0 wire [16: 6] w_p_r_A1_B0; // partial multiplication result A1*B0 wire [10: 0] w_p_r_A0_B0; // partial multiplication result A0*B0 wire [22:12] w_p_r_A1_B1; // partial multiplication result A1*B1 wire [16: 6] w_p_r_A0_B1; // partial multiplication result A0*B1 wire [22: 0] w_p_r_sum; // multiplication result assign w_p_A1[11: 6] = i_poly_form_A[11: 6]; assign w_p_A0[ 5: 0] = i_poly_form_A[ 5: 0]; assign w_p_B1[11: 6] = i_poly_form_B[11: 6]; assign w_p_B0[ 5: 0] = i_poly_form_B[ 5: 0]; // multipliers for partial multiplication d_partial_FFM_gate_6b p_mul_A1_B0 ( .i_a(w_p_A1[11: 6]), .i_b(w_p_B0[ 5: 0]), .o_r(w_p_r_A1_B0[16: 6])); d_partial_FFM_gate_6b p_mul_A0_B0 ( .i_a(w_p_A0[ 5: 0]), .i_b(w_p_B0[ 5: 0]), .o_r(w_p_r_A0_B0[10: 0])); d_partial_FFM_gate_6b p_mul_A1_B1 ( .i_a(w_p_A1[11: 6]), .i_b(w_p_B1[11: 6]), .o_r(w_p_r_A1_B1[22:12])); d_partial_FFM_gate_6b p_mul_A0_B1 ( .i_a(w_p_A0[ 5: 0]), .i_b(w_p_B1[11: 6]), .o_r(w_p_r_A0_B1[16: 6])); // sum partial results assign w_p_r_sum[22:17] = w_p_r_A1_B1[22:17]; assign w_p_r_sum[16:12] = w_p_r_A1_B1[16:12] ^ w_p_r_A0_B1[16:12] ^ w_p_r_A1_B0[16:12]; assign w_p_r_sum[11] = w_p_r_A0_B1[11] ^ w_p_r_A1_B0[11]; assign w_p_r_sum[10: 6] = w_p_r_A0_B1[10: 6] ^ w_p_r_A1_B0[10: 6] ^ w_p_r_A0_B0[10: 6]; assign w_p_r_sum[ 5: 0] = w_p_r_A0_B0[ 5: 0]; // reduce high order terms assign o_poly_form_result[11] = w_p_r_sum[11] ^ w_p_r_sum[16] ^ w_p_r_sum[19] ^ w_p_r_sum[20] ^ w_p_r_sum[21]; assign o_poly_form_result[10] = w_p_r_sum[10] ^ w_p_r_sum[15] ^ w_p_r_sum[18] ^ w_p_r_sum[19] ^ w_p_r_sum[20] ^ w_p_r_sum[22]; assign o_poly_form_result[ 9] = w_p_r_sum[ 9] ^ w_p_r_sum[14] ^ w_p_r_sum[17] ^ w_p_r_sum[18] ^ w_p_r_sum[19] ^ w_p_r_sum[21]; assign o_poly_form_result[ 8] = w_p_r_sum[ 8] ^ w_p_r_sum[13] ^ w_p_r_sum[16] ^ w_p_r_sum[17] ^ w_p_r_sum[18] ^ w_p_r_sum[20]; assign o_poly_form_result[ 7] = w_p_r_sum[ 7] ^ w_p_r_sum[12] ^ w_p_r_sum[15] ^ w_p_r_sum[16] ^ w_p_r_sum[17] ^ w_p_r_sum[19] ^ w_p_r_sum[22]; assign o_poly_form_result[ 6] = w_p_r_sum[ 6] ^ w_p_r_sum[14] ^ w_p_r_sum[15] ^ w_p_r_sum[18] ^ w_p_r_sum[19] ^ w_p_r_sum[20] ^ w_p_r_sum[22]; assign o_poly_form_result[ 5] = w_p_r_sum[ 5] ^ w_p_r_sum[13] ^ w_p_r_sum[14] ^ w_p_r_sum[17] ^ w_p_r_sum[18] ^ w_p_r_sum[19] ^ w_p_r_sum[21] ^ w_p_r_sum[22]; assign o_poly_form_result[ 4] = w_p_r_sum[ 4] ^ w_p_r_sum[12] ^ w_p_r_sum[13] ^ w_p_r_sum[16] ^ w_p_r_sum[17] ^ w_p_r_sum[18] ^ w_p_r_sum[20] ^ w_p_r_sum[21]; assign o_poly_form_result[ 3] = w_p_r_sum[ 3] ^ w_p_r_sum[12] ^ w_p_r_sum[15] ^ w_p_r_sum[17] ^ w_p_r_sum[21] ^ w_p_r_sum[22]; assign o_poly_form_result[ 2] = w_p_r_sum[ 2] ^ w_p_r_sum[14] ^ w_p_r_sum[19] ^ w_p_r_sum[22]; assign o_poly_form_result[ 1] = w_p_r_sum[ 1] ^ w_p_r_sum[13] ^ w_p_r_sum[18] ^ w_p_r_sum[21] ^ w_p_r_sum[22]; assign o_poly_form_result[ 0] = w_p_r_sum[ 0] ^ w_p_r_sum[12] ^ w_p_r_sum[17] ^ w_p_r_sum[20] ^ w_p_r_sum[21] ^ w_p_r_sum[22]; endmodule
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * 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. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // 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 REGENTS OF THE // UNIVERSITY OF CALIFORNIA 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. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: tx_hdr_fifo.v // Version: 1.0 // Verilog Standard: Verilog-2001 // // Description: The tx_hdr_fifo module implements a simple fifo for a packet // (WR_TX_HDR) header and three metadata signals: WR_TX_HDR_ABLANKS, // WR_TX_HDR_LEN, WR_TX_HDR_NOPAYLOAD. NOPAYLOAD indicates that the header is not // followed by a payload. HDR_LEN indicates the length of the header in // dwords. The ABLANKS signal indicates how many dwords should be inserted between // the header and payload. // // The intended use for this module is between the interface specific tx formatter // (TXC or TXR) and the alignment pipeline, in parallel with the tx_data_pipeline // which contains a fifo for payloads. // // Author: Dustin Richmond (@darichmond) // Co-Authors: //---------------------------------------------------------------------------- `timescale 1ns/1ns `include "trellis.vh" // Defines the user-facing signal widths. module tx_hdr_fifo #(parameter C_DEPTH_PACKETS = 10, parameter C_MAX_HDR_WIDTH = 128, parameter C_PIPELINE_OUTPUT = 1, parameter C_PIPELINE_INPUT = 1, parameter C_VENDOR = "ALTERA" ) ( // Interface: Clocks input CLK, // Interface: Reset input RST_IN, // Interface: WR_TX_HDR input WR_TX_HDR_VALID, input [(C_MAX_HDR_WIDTH)-1:0] WR_TX_HDR, input [`SIG_LEN_W-1:0] WR_TX_HDR_PAYLOAD_LEN, input [`SIG_NONPAY_W-1:0] WR_TX_HDR_NONPAY_LEN, input [`SIG_PACKETLEN_W-1:0] WR_TX_HDR_PACKET_LEN, input WR_TX_HDR_NOPAYLOAD, output WR_TX_HDR_READY, // Interface: RD_TX_HDR output RD_TX_HDR_VALID, output [(C_MAX_HDR_WIDTH)-1:0] RD_TX_HDR, output [`SIG_LEN_W-1:0] RD_TX_HDR_PAYLOAD_LEN, output [`SIG_NONPAY_W-1:0] RD_TX_HDR_NONPAY_LEN, output [`SIG_PACKETLEN_W-1:0] RD_TX_HDR_PACKET_LEN, output RD_TX_HDR_NOPAYLOAD, input RD_TX_HDR_READY ); // Size of the header, plus the three metadata signals localparam C_WIDTH = (C_MAX_HDR_WIDTH) + `SIG_NONPAY_W + `SIG_PACKETLEN_W + 1 + `SIG_LEN_W; wire RST; wire wWrTxHdrReady; wire wWrTxHdrValid; wire [(C_MAX_HDR_WIDTH)-1:0] wWrTxHdr; wire [`SIG_NONPAY_W-1:0] wWrTxHdrNonpayLen; wire [`SIG_PACKETLEN_W-1:0] wWrTxHdrPacketLen; wire [`SIG_LEN_W-1:0] wWrTxHdrPayloadLen; wire wWrTxHdrNoPayload; wire wRdTxHdrReady; wire wRdTxHdrValid; wire [C_MAX_HDR_WIDTH-1:0] wRdTxHdr; wire [`SIG_NONPAY_W-1:0] wRdTxHdrNonpayLen; wire [`SIG_PACKETLEN_W-1:0] wRdTxHdrPacketLen; wire [`SIG_LEN_W-1:0] wRdTxHdrPayloadLen; wire wRdTxHdrNoPayload; assign RST = RST_IN; pipeline #( .C_DEPTH (C_PIPELINE_INPUT?1:0), .C_USE_MEMORY (0), /*AUTOINSTPARAM*/ // Parameters .C_WIDTH (C_WIDTH)) input_pipeline_inst ( // Outputs .WR_DATA_READY (WR_TX_HDR_READY), .RD_DATA ({wWrTxHdr,wWrTxHdrNonpayLen,wWrTxHdrPacketLen,wWrTxHdrPayloadLen,wWrTxHdrNoPayload}), .RD_DATA_VALID (wWrTxHdrValid), // Inputs .WR_DATA ({WR_TX_HDR,WR_TX_HDR_NONPAY_LEN,WR_TX_HDR_PACKET_LEN,WR_TX_HDR_PAYLOAD_LEN,WR_TX_HDR_NOPAYLOAD}), .WR_DATA_VALID (WR_TX_HDR_VALID), .RD_DATA_READY (wWrTxHdrReady), /*AUTOINST*/ // Inputs .CLK (CLK), .RST_IN (RST_IN)); fifo #( // Parameters .C_DELAY (0), /*AUTOINSTPARAM*/ // Parameters .C_WIDTH (C_WIDTH), .C_DEPTH (C_DEPTH_PACKETS)) fifo_inst ( // Outputs .RD_DATA ({wRdTxHdr,wRdTxHdrNonpayLen,wRdTxHdrPacketLen,wRdTxHdrPayloadLen,wRdTxHdrNoPayload}), .WR_READY (wWrTxHdrReady), .RD_VALID (wRdTxHdrValid), // Inputs .WR_DATA ({wWrTxHdr,wWrTxHdrNonpayLen,wWrTxHdrPacketLen,wWrTxHdrPayloadLen,wWrTxHdrNoPayload}), .WR_VALID (wWrTxHdrValid), .RD_READY (wRdTxHdrReady), /*AUTOINST*/ // Inputs .CLK (CLK), .RST (RST)); pipeline #( .C_DEPTH (C_PIPELINE_OUTPUT?1:0), .C_USE_MEMORY (0), /*AUTOINSTPARAM*/ // Parameters .C_WIDTH (C_WIDTH)) output_pipeline_inst ( // Outputs .WR_DATA_READY (wRdTxHdrReady), .RD_DATA ({RD_TX_HDR,RD_TX_HDR_NONPAY_LEN,RD_TX_HDR_PACKET_LEN,RD_TX_HDR_PAYLOAD_LEN,RD_TX_HDR_NOPAYLOAD}), .RD_DATA_VALID (RD_TX_HDR_VALID), // Inputs .WR_DATA ({wRdTxHdr,wRdTxHdrNonpayLen,wRdTxHdrPacketLen,wRdTxHdrPayloadLen,wRdTxHdrNoPayload}), .WR_DATA_VALID (wRdTxHdrValid), .RD_DATA_READY (RD_TX_HDR_READY), /*AUTOINST*/ // Inputs .CLK (CLK), .RST_IN (RST_IN)); endmodule // Local Variables: // verilog-library-directories:("." "../../common/") // End:
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * 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. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // 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 REGENTS OF THE // UNIVERSITY OF CALIFORNIA 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. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: one_hot_mux.v // Version: 1.00.a // Verilog Standard: Verilog-2001 // Description: A mux module, where the output select is a one-hot bus // Author: Dustin Richmond //----------------------------------------------------------------------------- `timescale 1ns/1ns `include "functions.vh" module one_hot_mux #(parameter C_DATA_WIDTH = 1, parameter C_SELECT_WIDTH = 2, parameter C_AGGREGATE_WIDTH = C_SELECT_WIDTH*C_DATA_WIDTH ) ( input [C_SELECT_WIDTH-1:0] ONE_HOT_SELECT, input [C_AGGREGATE_WIDTH-1:0] ONE_HOT_INPUTS, output [C_DATA_WIDTH-1:0] ONE_HOT_OUTPUT); genvar i; wire [C_DATA_WIDTH-1:0] wOneHotInputs[(1<<C_SELECT_WIDTH):1]; reg [C_DATA_WIDTH-1:0] _rOneHotOutput; assign ONE_HOT_OUTPUT = _rOneHotOutput; generate for( i = 0 ; i < C_SELECT_WIDTH; i = i + 1 ) begin : gen_input_array assign wOneHotInputs[(1<<i)] = ONE_HOT_INPUTS[C_DATA_WIDTH*i +: C_DATA_WIDTH]; end if(C_SELECT_WIDTH == 1) begin always @(*) begin _rOneHotOutput = wOneHotInputs[1]; end end else if(C_SELECT_WIDTH == 2) begin always @(*) begin case(ONE_HOT_SELECT) 2'b01: _rOneHotOutput = wOneHotInputs[1]; 2'b10: _rOneHotOutput = wOneHotInputs[2]; default:_rOneHotOutput = wOneHotInputs[1]; endcase // case (ONE_HOT_SELECT) end end else if( C_SELECT_WIDTH == 4) begin always @(*) begin case(ONE_HOT_SELECT) 4'b0001: _rOneHotOutput = wOneHotInputs[1]; 4'b0010: _rOneHotOutput = wOneHotInputs[2]; 4'b0100: _rOneHotOutput = wOneHotInputs[4]; 4'b1000: _rOneHotOutput = wOneHotInputs[8]; default:_rOneHotOutput = wOneHotInputs[1]; endcase // case (ONE_HOT_SELECT) end end else if( C_SELECT_WIDTH == 8) begin always @(*) begin case(ONE_HOT_SELECT) 8'b00000001: _rOneHotOutput = wOneHotInputs[1]; 8'b00000010: _rOneHotOutput = wOneHotInputs[2]; 8'b00000100: _rOneHotOutput = wOneHotInputs[4]; 8'b00001000: _rOneHotOutput = wOneHotInputs[8]; 8'b00010000: _rOneHotOutput = wOneHotInputs[16]; 8'b00100000: _rOneHotOutput = wOneHotInputs[32]; 8'b01000000: _rOneHotOutput = wOneHotInputs[64]; 8'b10000000: _rOneHotOutput = wOneHotInputs[128]; default:_rOneHotOutput = wOneHotInputs[1]; endcase // case (ONE_HOT_SELECT) end end endgenerate endmodule
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * 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. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // 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 REGENTS OF THE // UNIVERSITY OF CALIFORNIA 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. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: one_hot_mux.v // Version: 1.00.a // Verilog Standard: Verilog-2001 // Description: A mux module, where the output select is a one-hot bus // Author: Dustin Richmond //----------------------------------------------------------------------------- `timescale 1ns/1ns `include "functions.vh" module one_hot_mux #(parameter C_DATA_WIDTH = 1, parameter C_SELECT_WIDTH = 2, parameter C_AGGREGATE_WIDTH = C_SELECT_WIDTH*C_DATA_WIDTH ) ( input [C_SELECT_WIDTH-1:0] ONE_HOT_SELECT, input [C_AGGREGATE_WIDTH-1:0] ONE_HOT_INPUTS, output [C_DATA_WIDTH-1:0] ONE_HOT_OUTPUT); genvar i; wire [C_DATA_WIDTH-1:0] wOneHotInputs[(1<<C_SELECT_WIDTH):1]; reg [C_DATA_WIDTH-1:0] _rOneHotOutput; assign ONE_HOT_OUTPUT = _rOneHotOutput; generate for( i = 0 ; i < C_SELECT_WIDTH; i = i + 1 ) begin : gen_input_array assign wOneHotInputs[(1<<i)] = ONE_HOT_INPUTS[C_DATA_WIDTH*i +: C_DATA_WIDTH]; end if(C_SELECT_WIDTH == 1) begin always @(*) begin _rOneHotOutput = wOneHotInputs[1]; end end else if(C_SELECT_WIDTH == 2) begin always @(*) begin case(ONE_HOT_SELECT) 2'b01: _rOneHotOutput = wOneHotInputs[1]; 2'b10: _rOneHotOutput = wOneHotInputs[2]; default:_rOneHotOutput = wOneHotInputs[1]; endcase // case (ONE_HOT_SELECT) end end else if( C_SELECT_WIDTH == 4) begin always @(*) begin case(ONE_HOT_SELECT) 4'b0001: _rOneHotOutput = wOneHotInputs[1]; 4'b0010: _rOneHotOutput = wOneHotInputs[2]; 4'b0100: _rOneHotOutput = wOneHotInputs[4]; 4'b1000: _rOneHotOutput = wOneHotInputs[8]; default:_rOneHotOutput = wOneHotInputs[1]; endcase // case (ONE_HOT_SELECT) end end else if( C_SELECT_WIDTH == 8) begin always @(*) begin case(ONE_HOT_SELECT) 8'b00000001: _rOneHotOutput = wOneHotInputs[1]; 8'b00000010: _rOneHotOutput = wOneHotInputs[2]; 8'b00000100: _rOneHotOutput = wOneHotInputs[4]; 8'b00001000: _rOneHotOutput = wOneHotInputs[8]; 8'b00010000: _rOneHotOutput = wOneHotInputs[16]; 8'b00100000: _rOneHotOutput = wOneHotInputs[32]; 8'b01000000: _rOneHotOutput = wOneHotInputs[64]; 8'b10000000: _rOneHotOutput = wOneHotInputs[128]; default:_rOneHotOutput = wOneHotInputs[1]; endcase // case (ONE_HOT_SELECT) end end endgenerate 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 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 $write("%%Error: t_vpi_var.cpp:%0d: C Test failed\n", status); $stop; end for (i = 16; i > 0; i--) if (mem0[i] !== i) begin $write("%%Error: %d : GOT = %d EXP = %d\n", i, mem0[i], i); status = 1; end if (status!=0) begin $write("%%Error: t_vpi_var.cpp:%0d: C Test failed\n", status); $stop; end $write("*-* All Finished *-*\n"); $finish; end endmodule : t
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * 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. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // 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 REGENTS OF THE // UNIVERSITY OF CALIFORNIA 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. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: txr_engine_ultrascale.v // Version: 1.0 // Verilog Standard: Verilog-2001 // Description: The TXR Engine takes unformatted completions, formats // these packets into AXI-style packets. These packets must meet max-request, // max-payload, and payload termination requirements (see Read Completion // Boundary). The TXR Engine does not check these requirements during operation, // but may do so during simulation. // // This Engine is capable of operating at "line rate". // // Author: Dustin Richmond (@darichmond) //----------------------------------------------------------------------------- `include "trellis.vh" `include "ultrascale.vh" module txr_engine_ultrascale #(parameter C_PCI_DATA_WIDTH = 128, parameter C_PIPELINE_INPUT = 1, parameter C_PIPELINE_OUTPUT = 1, parameter C_DEPTH_PACKETS = 10, parameter C_MAX_PAYLOAD_DWORDS = 256) (// Interface: Clocks input CLK, // Interface: Resets input RST_BUS, // Replacement for generic RST_IN input RST_LOGIC, // Addition for RIFFA_RST output DONE_TXR_RST, // Interface: Configuration input [`SIG_CPLID_W-1:0] CONFIG_COMPLETER_ID, // Interface: RQ input S_AXIS_RQ_TREADY, output S_AXIS_RQ_TVALID, output S_AXIS_RQ_TLAST, output [C_PCI_DATA_WIDTH-1:0] S_AXIS_RQ_TDATA, output [(C_PCI_DATA_WIDTH/32)-1:0] S_AXIS_RQ_TKEEP, output [`SIG_RQ_TUSER_W-1:0] S_AXIS_RQ_TUSER, // Interface: TXR Engine input TXR_DATA_VALID, input [C_PCI_DATA_WIDTH-1:0] TXR_DATA, input TXR_DATA_START_FLAG, input [clog2s(C_PCI_DATA_WIDTH/32)-1:0] TXR_DATA_START_OFFSET, input TXR_DATA_END_FLAG, input [clog2s(C_PCI_DATA_WIDTH/32)-1:0] TXR_DATA_END_OFFSET, output TXR_DATA_READY, input TXR_META_VALID, input [`SIG_FBE_W-1:0] TXR_META_FDWBE, input [`SIG_LBE_W-1:0] TXR_META_LDWBE, input [`SIG_ADDR_W-1:0] TXR_META_ADDR, input [`SIG_LEN_W-1:0] TXR_META_LENGTH, input [`SIG_TAG_W-1:0] TXR_META_TAG, input [`SIG_TC_W-1:0] TXR_META_TC, input [`SIG_ATTR_W-1:0] TXR_META_ATTR, input [`SIG_TYPE_W-1:0] TXR_META_TYPE, input TXR_META_EP, output TXR_META_READY ); localparam C_VENDOR = "XILINX"; localparam C_DATA_WIDTH = C_PCI_DATA_WIDTH; localparam C_MAX_HDR_WIDTH = `UPKT_TXR_MAXHDR_W; localparam C_MAX_HDR_DWORDS = C_MAX_HDR_WIDTH/32; localparam C_MAX_ALIGN_DWORDS = 0; localparam C_MAX_NONPAY_DWORDS = C_MAX_HDR_DWORDS + C_MAX_ALIGN_DWORDS + 1; localparam C_MAX_PACKET_DWORDS = C_MAX_NONPAY_DWORDS + C_MAX_PAYLOAD_DWORDS; localparam C_PIPELINE_FORMATTER_INPUT = C_PIPELINE_INPUT; localparam C_PIPELINE_FORMATTER_OUTPUT = C_PIPELINE_OUTPUT; localparam C_FORMATTER_DELAY = C_PIPELINE_FORMATTER_OUTPUT + C_PIPELINE_FORMATTER_INPUT; localparam C_RST_COUNT = 10; /*AUTOWIRE*/ /*AUTOINPUT*/ ///*AUTOOUTPUT*/ wire wTxHdrReady; wire wTxHdrValid; wire [C_MAX_HDR_WIDTH-1:0] wTxHdr; wire [`SIG_NONPAY_W-1:0] wTxHdrNonpayLen; wire [`SIG_PACKETLEN_W-1:0] wTxHdrPacketLen; wire [`SIG_LEN_W-1:0] wTxHdrPayloadLen; wire wTxHdrNopayload; wire wTxDataReady; wire [C_PCI_DATA_WIDTH-1:0] wTxData; wire [clog2s(C_PCI_DATA_WIDTH/32)-1:0] wTxDataEndOffset; wire wTxDataStartFlag; wire [(C_PCI_DATA_WIDTH/32)-1:0] wTxDataEndFlags; wire [(C_PCI_DATA_WIDTH/32)-1:0] wTxDataWordValid; wire [(C_PCI_DATA_WIDTH/32)-1:0] wTxDataWordReady; wire [C_PCI_DATA_WIDTH-1:0] wTxrPkt; wire wTxrPktEndFlag; wire [clog2s(C_PCI_DATA_WIDTH/32)-1:0] wTxrPktEndOffset; wire wTxrPktStartFlag; wire [clog2s(C_PCI_DATA_WIDTH/32)-1:0] wTxrPktStartOffset; wire wTxrPktValid; wire wTxrPktReady; wire wTransDoneRst; wire wTransRstOut; wire wDoneEngRst; wire wRst; wire [C_RST_COUNT:0] wShiftRegRst; assign DONE_TXR_RST = wTransDoneRst & wDoneEngRst; assign wRst = wShiftRegRst[C_RST_COUNT-3]; assign wDoneEngRst = ~wShiftRegRst[C_RST_COUNT]; shiftreg #(// Parameters .C_DEPTH (C_RST_COUNT), .C_WIDTH (1), .C_VALUE (1) /*AUTOINSTPARAM*/) rst_shiftreg (// Outputs .RD_DATA (wShiftRegRst), // Inputs .RST_IN (RST_BUS), .WR_DATA (wTransRstOut), /*AUTOINST*/ // Inputs .CLK (CLK)); txr_formatter_ultrascale #(.C_PIPELINE_OUTPUT (C_PIPELINE_FORMATTER_OUTPUT), .C_PIPELINE_INPUT (C_PIPELINE_FORMATTER_INPUT), /*AUTOINSTPARAM*/ // Parameters .C_PCI_DATA_WIDTH (C_PCI_DATA_WIDTH), .C_MAX_HDR_WIDTH (C_MAX_HDR_WIDTH), .C_MAX_NONPAY_DWORDS (C_MAX_NONPAY_DWORDS), .C_MAX_PACKET_DWORDS (C_MAX_PACKET_DWORDS)) txr_formatter_inst (// Outputs .TX_HDR_VALID (wTxHdrValid), .TX_HDR (wTxHdr[C_MAX_HDR_WIDTH-1:0]), .TX_HDR_NOPAYLOAD (wTxHdrNopayload), .TX_HDR_PAYLOAD_LEN (wTxHdrPayloadLen[`SIG_LEN_W-1:0]), .TX_HDR_NONPAY_LEN (wTxHdrNonpayLen[`SIG_NONPAY_W-1:0]), .TX_HDR_PACKET_LEN (wTxHdrPacketLen[`SIG_PACKETLEN_W-1:0]), // Inputs .TX_HDR_READY (wTxHdrReady), .RST_IN (wRst), /*AUTOINST*/ // Outputs .TXR_META_READY (TXR_META_READY), // Inputs .CLK (CLK), .CONFIG_COMPLETER_ID (CONFIG_COMPLETER_ID[`SIG_CPLID_W-1:0]), .TXR_META_VALID (TXR_META_VALID), .TXR_META_FDWBE (TXR_META_FDWBE[`SIG_FBE_W-1:0]), .TXR_META_LDWBE (TXR_META_LDWBE[`SIG_LBE_W-1:0]), .TXR_META_ADDR (TXR_META_ADDR[`SIG_ADDR_W-1:0]), .TXR_META_LENGTH (TXR_META_LENGTH[`SIG_LEN_W-1:0]), .TXR_META_TAG (TXR_META_TAG[`SIG_TAG_W-1:0]), .TXR_META_TC (TXR_META_TC[`SIG_TC_W-1:0]), .TXR_META_ATTR (TXR_META_ATTR[`SIG_ATTR_W-1:0]), .TXR_META_TYPE (TXR_META_TYPE[`SIG_TYPE_W-1:0]), .TXR_META_EP (TXR_META_EP)); tx_engine #(.C_DATA_WIDTH (C_PCI_DATA_WIDTH), /*AUTOINSTPARAM*/ // Parameters .C_DEPTH_PACKETS (C_DEPTH_PACKETS), .C_PIPELINE_INPUT (C_PIPELINE_INPUT), .C_PIPELINE_OUTPUT (C_PIPELINE_OUTPUT), .C_FORMATTER_DELAY (C_FORMATTER_DELAY), .C_MAX_HDR_WIDTH (C_MAX_HDR_WIDTH), .C_MAX_PAYLOAD_DWORDS (C_MAX_PAYLOAD_DWORDS), .C_VENDOR (C_VENDOR)) txr_engine_inst (// Outputs .TX_HDR_READY (wTxHdrReady), .TX_DATA_READY (TXR_DATA_READY), .TX_PKT (wTxrPkt[C_DATA_WIDTH-1:0]), .TX_PKT_START_FLAG (wTxrPktStartFlag), .TX_PKT_START_OFFSET (wTxrPktStartOffset[clog2s(C_DATA_WIDTH/32)-1:0]), .TX_PKT_END_FLAG (wTxrPktEndFlag), .TX_PKT_END_OFFSET (wTxrPktEndOffset[clog2s(C_DATA_WIDTH/32)-1:0]), .TX_PKT_VALID (wTxrPktValid), // Inputs .TX_HDR_VALID (wTxHdrValid), .TX_HDR (wTxHdr[C_MAX_HDR_WIDTH-1:0]), .TX_HDR_NOPAYLOAD (wTxHdrNopayload), .TX_HDR_PAYLOAD_LEN (wTxHdrPayloadLen[`SIG_LEN_W-1:0]), .TX_HDR_NONPAY_LEN (wTxHdrNonpayLen[`SIG_NONPAY_W-1:0]), .TX_HDR_PACKET_LEN (wTxHdrPacketLen[`SIG_PACKETLEN_W-1:0]), .TX_DATA_VALID (TXR_DATA_VALID), .TX_DATA (TXR_DATA[C_DATA_WIDTH-1:0]), .TX_DATA_START_FLAG (TXR_DATA_START_FLAG), .TX_DATA_START_OFFSET (TXR_DATA_START_OFFSET[clog2s(C_DATA_WIDTH/32)-1:0]), .TX_DATA_END_FLAG (TXR_DATA_END_FLAG), .TX_DATA_END_OFFSET (TXR_DATA_END_OFFSET[clog2s(C_DATA_WIDTH/32)-1:0]), .TX_PKT_READY (wTxrPktReady), .RST_IN (wRst),// TODO: /*AUTOINST*/ // Inputs .CLK (CLK)); txr_translation_layer #(/*AUTOINSTPARAM*/ // Parameters .C_PCI_DATA_WIDTH (C_PCI_DATA_WIDTH), .C_PIPELINE_INPUT (C_PIPELINE_INPUT), .C_RST_COUNT (C_RST_COUNT)) txr_trans_inst (// Outputs .TXR_PKT_READY (wTxrPktReady), .DONE_RST (wTransDoneRst), .RST_OUT (wTransRstOut), // Inputs .TXR_PKT (wTxrPkt), .TXR_PKT_VALID (wTxrPktValid), .TXR_PKT_START_FLAG (wTxrPktStartFlag), .TXR_PKT_START_OFFSET (wTxrPktStartOffset), .TXR_PKT_END_FLAG (wTxrPktEndFlag), .TXR_PKT_END_OFFSET (wTxrPktEndOffset), /*AUTOINST*/ // Outputs .S_AXIS_RQ_TVALID (S_AXIS_RQ_TVALID), .S_AXIS_RQ_TLAST (S_AXIS_RQ_TLAST), .S_AXIS_RQ_TDATA (S_AXIS_RQ_TDATA[C_PCI_DATA_WIDTH-1:0]), .S_AXIS_RQ_TKEEP (S_AXIS_RQ_TKEEP[(C_PCI_DATA_WIDTH/32)-1:0]), .S_AXIS_RQ_TUSER (S_AXIS_RQ_TUSER[`SIG_RQ_TUSER_W-1:0]), // Inputs .CLK (CLK), .RST_BUS (RST_BUS), .RST_LOGIC (RST_LOGIC), .S_AXIS_RQ_TREADY (S_AXIS_RQ_TREADY)); endmodule // txr_engine_ultrascale module txr_formatter_ultrascale #( parameter C_PCI_DATA_WIDTH = 128, parameter C_PIPELINE_INPUT = 1, parameter C_PIPELINE_OUTPUT = 1, parameter C_MAX_HDR_WIDTH = `UPKT_TXR_MAXHDR_W, parameter C_MAX_NONPAY_DWORDS = 5, parameter C_MAX_PACKET_DWORDS = 10 ) ( // Interface: Clocks input CLK, // Interface: Resets input RST_IN, // Interface: Configuration input [`SIG_CPLID_W-1:0] CONFIG_COMPLETER_ID, // Interface: TXR input TXR_META_VALID, input [`SIG_FBE_W-1:0] TXR_META_FDWBE, input [`SIG_LBE_W-1:0] TXR_META_LDWBE, input [`SIG_ADDR_W-1:0] TXR_META_ADDR, input [`SIG_LEN_W-1:0] TXR_META_LENGTH, input [`SIG_TAG_W-1:0] TXR_META_TAG, input [`SIG_TC_W-1:0] TXR_META_TC, input [`SIG_ATTR_W-1:0] TXR_META_ATTR, input [`SIG_TYPE_W-1:0] TXR_META_TYPE, input TXR_META_EP, output TXR_META_READY, // Interface: TX HDR output TX_HDR_VALID, output [C_MAX_HDR_WIDTH-1:0] TX_HDR, output [`SIG_LEN_W-1:0] TX_HDR_PAYLOAD_LEN, output [`SIG_NONPAY_W-1:0] TX_HDR_NONPAY_LEN, output [`SIG_PACKETLEN_W-1:0] TX_HDR_PACKET_LEN, output TX_HDR_NOPAYLOAD, input TX_HDR_READY ); wire wHdrNoPayload; wire [`UPKT_TXR_MAXHDR_W-1:0] wHdr; wire wTxHdrReady; wire wTxHdrValid; wire [`UPKT_TXR_MAXHDR_W-1:0] wTxHdr; wire [`SIG_NONPAY_W-1:0] wTxHdrNonpayLen; wire [`SIG_PACKETLEN_W-1:0] wTxHdrPacketLen; wire [`SIG_LEN_W-1:0] wTxHdrPayloadLen; wire wTxHdrNopayload; wire [`SIG_TYPE_W-1:0] wTxHdrType; // Generic Header Fields assign wHdr[`UPKT_TXR_ATYPE_R] = `UPKT_TXR_ATYPE_W'd0; assign wHdr[`UPKT_TXR_ADDR_R] = TXR_META_ADDR[63:2]; assign wHdr[`UPKT_TXR_LENGTH_R] = {1'b0,TXR_META_LENGTH}; assign wHdr[`UPKT_TXR_EP_R] = TXR_META_EP; `ifdef BE_HACK assign wHdr[`UPKT_TXR_FBE_R] = TXR_META_FDWBE; assign wHdr[`UPKT_TXR_LBE_R] = TXR_META_LDWBE; assign wHdr[`UPKT_TXR_RSVD0_R] = 0; `else assign wHdr[`UPKT_TXR_REQID_R] = CONFIG_COMPLETER_ID; `endif //assign wHdr[`UPKT_TXR_REQID_R] = `UPKT_TXR_REQID_W'd0; assign wHdr[`UPKT_TXR_TAG_R] = TXR_META_TAG; assign wHdr[`UPKT_TXR_CPLID_R] = `UPKT_TXR_CPLID_W'd0; assign wHdr[`UPKT_TXR_REQIDEN_R] = 0; assign wHdr[`UPKT_TXR_TC_R] = TXR_META_TC; assign wHdr[`UPKT_TXR_ATTR_R] = TXR_META_ATTR; assign wHdr[`UPKT_TXR_TD_R] = `UPKT_TXR_TD_W'd0; assign wTxHdr[`UPKT_TXR_TYPE_R] = trellis_to_upkt_type(wTxHdrType); assign wTxHdrNopayload = ~wTxHdrType[`TRLS_TYPE_PAY_I]; assign wTxHdrNonpayLen = 4; assign wTxHdrPayloadLen = wTxHdrNopayload ? 0 : wTxHdr[`UPKT_TXR_LENGTH_R]; assign wTxHdrPacketLen = wTxHdrNonpayLen + wTxHdrPayloadLen; pipeline #( // Parameters .C_DEPTH (C_PIPELINE_INPUT?1:0), .C_WIDTH (`UPKT_TXR_MAXHDR_W-1), .C_USE_MEMORY (0) /*AUTOINSTPARAM*/) input_inst ( // Outputs .WR_DATA_READY (TXR_META_READY), .RD_DATA ({wTxHdr[`UPKT_TXR_MAXHDR_W-1:(`UPKT_TXR_TYPE_I + `UPKT_TXR_TYPE_W)], wTxHdr[`UPKT_TXR_TYPE_I-1:0], wTxHdrType}), .RD_DATA_VALID (wTxHdrValid), // Inputs .WR_DATA ({wHdr[`UPKT_TXR_MAXHDR_W-1:(`UPKT_TXR_TYPE_I + `UPKT_TXR_TYPE_W)], wHdr[`UPKT_TXR_TYPE_I-1:0], TXR_META_TYPE}), .WR_DATA_VALID (TXR_META_VALID), .RD_DATA_READY (wTxHdrReady), /*AUTOINST*/ // Inputs .CLK (CLK), .RST_IN (RST_IN)); pipeline #( // Parameters .C_DEPTH (C_PIPELINE_OUTPUT?1:0), .C_WIDTH (`UPKT_TXR_MAXHDR_W + 1 + `SIG_PACKETLEN_W + `SIG_LEN_W + `SIG_NONPAY_W), .C_USE_MEMORY (0) /*AUTOINSTPARAM*/) output_inst ( // Outputs .WR_DATA_READY (wTxHdrReady), .RD_DATA ({TX_HDR,TX_HDR_NOPAYLOAD,TX_HDR_PACKET_LEN,TX_HDR_PAYLOAD_LEN,TX_HDR_NONPAY_LEN}), .RD_DATA_VALID (TX_HDR_VALID), // Inputs .WR_DATA ({wTxHdr,wTxHdrNopayload,wTxHdrPacketLen,wTxHdrPayloadLen,wTxHdrNonpayLen}), .WR_DATA_VALID (wTxHdrValid), .RD_DATA_READY (TX_HDR_READY), /*AUTOINST*/ // Inputs .CLK (CLK), .RST_IN (RST_IN)); endmodule module txr_translation_layer #(parameter C_PCI_DATA_WIDTH = 10'd128, parameter C_PIPELINE_INPUT = 1, parameter C_RST_COUNT = 1) (// Interface: Clocks input CLK, // Interface: Resets input RST_BUS, // Replacement for generic RST_IN input RST_LOGIC, // Addition for RIFFA_RST output RST_OUT, output DONE_RST, // Interface: TXR Classic output TXR_PKT_READY, input [C_PCI_DATA_WIDTH-1:0] TXR_PKT, input TXR_PKT_VALID, input TXR_PKT_START_FLAG, input [clog2s(C_PCI_DATA_WIDTH/32)-1:0] TXR_PKT_START_OFFSET, input TXR_PKT_END_FLAG, input [clog2s(C_PCI_DATA_WIDTH/32)-1:0] TXR_PKT_END_OFFSET, // Interface: RQ input S_AXIS_RQ_TREADY, output S_AXIS_RQ_TVALID, output S_AXIS_RQ_TLAST, output [C_PCI_DATA_WIDTH-1:0] S_AXIS_RQ_TDATA, output [(C_PCI_DATA_WIDTH/32)-1:0] S_AXIS_RQ_TKEEP, output [`SIG_RQ_TUSER_W-1:0] S_AXIS_RQ_TUSER); localparam C_INPUT_STAGES = C_PIPELINE_INPUT != 0? 1:0; localparam C_OUTPUT_STAGES = 1; wire wTxrPktReady; wire [C_PCI_DATA_WIDTH-1:0] wTxrPkt; wire wTxrPktValid; wire wTxrPktStartFlag; wire [clog2s(C_PCI_DATA_WIDTH/32)-1:0] wTxrPktStartOffset; wire wTxrPktEndFlag; wire [clog2s(C_PCI_DATA_WIDTH/32)-1:0] wTxrPktEndOffset; wire wSAxisRqTReady; wire wSAxisRqTValid; wire wSAxisRqTLast; wire [C_PCI_DATA_WIDTH-1:0] wSAxisRqTData; wire [(C_PCI_DATA_WIDTH/32)-1:0] wSAxisRqTKeep; wire [`SIG_RQ_TUSER_W-1:0] wSAxisRqTUser; wire _wSAxisRqTReady; wire _wSAxisRqTValid; wire _wSAxisRqTLast; wire [C_PCI_DATA_WIDTH-1:0] _wSAxisRqTData; wire [(C_PCI_DATA_WIDTH/32)-1:0] _wSAxisRqTKeep; wire wRst; wire wRstWaiting; /*ASSIGN TXR -> RQ*/ assign wTxrPktReady = _wSAxisRqTReady; assign _wSAxisRqTValid = wTxrPktValid; assign _wSAxisRqTLast = wTxrPktEndFlag; assign _wSAxisRqTData = wTxrPkt; // BE Hack assign wSAxisRqTUser[3:0] = wTxrPkt[(`UPKT_TXR_FBE_I % C_PCI_DATA_WIDTH) +: `UPKT_TXR_FBE_W]; assign wSAxisRqTUser[7:4] = wTxrPkt[(`UPKT_TXR_LBE_I % C_PCI_DATA_WIDTH) +: `UPKT_TXR_LBE_W]; assign wSAxisRqTUser[`SIG_RQ_TUSER_W-1:8] = 0; assign RST_OUT = wRst; // This reset controller assumes there is always an output stage reset_controller #(/*AUTOINSTPARAM*/ // Parameters .C_RST_COUNT (C_RST_COUNT)) rc (// Outputs .RST_OUT (wRst), .WAITING_RESET (wRstWaiting), // Inputs .RST_IN (RST_BUS), .SIGNAL_RST (RST_LOGIC), .WAIT_RST (S_AXIS_RQ_TVALID), .NEXT_CYC_RST (S_AXIS_RQ_TREADY & S_AXIS_RQ_TLAST), /*AUTOINST*/ // Outputs .DONE_RST (DONE_RST), // Inputs .CLK (CLK)); pipeline #(// Parameters .C_DEPTH (C_INPUT_STAGES), .C_WIDTH (C_PCI_DATA_WIDTH + 2*(1+clog2s(C_PCI_DATA_WIDTH/32))), .C_USE_MEMORY (0) /*AUTOINSTPARAM*/) input_inst ( // Outputs .WR_DATA_READY (TXR_PKT_READY), .RD_DATA ({wTxrPkt,wTxrPktStartFlag,wTxrPktStartOffset,wTxrPktEndFlag,wTxrPktEndOffset}), .RD_DATA_VALID (wTxrPktValid), // Inputs .WR_DATA ({TXR_PKT,TXR_PKT_START_FLAG,TXR_PKT_START_OFFSET, TXR_PKT_END_FLAG,TXR_PKT_END_OFFSET}), .WR_DATA_VALID (TXR_PKT_VALID), .RD_DATA_READY (wTxrPktReady), .RST_IN (wRst), /*AUTOINST*/ // Inputs .CLK (CLK)); offset_to_mask #( // Parameters .C_MASK_SWAP (0), .C_MASK_WIDTH (C_PCI_DATA_WIDTH/32) /*AUTOINSTPARAM*/) otom_inst ( // Outputs .MASK (_wSAxisRqTKeep), // Inputs .OFFSET_ENABLE (wTxrPktEndFlag), .OFFSET (wTxrPktEndOffset) /*AUTOINST*/); pipeline #( // Parameters .C_DEPTH (64/C_PCI_DATA_WIDTH), .C_WIDTH (C_PCI_DATA_WIDTH + 1 + (C_PCI_DATA_WIDTH/32)), .C_USE_MEMORY (0) /*AUTOINSTPARAM*/) fbe_hack_inst ( // Outputs .WR_DATA_READY (_wSAxisRqTReady), .RD_DATA ({wSAxisRqTData,wSAxisRqTLast,wSAxisRqTKeep}), .RD_DATA_VALID (wSAxisRqTValid), // Inputs .WR_DATA ({_wSAxisRqTData,_wSAxisRqTLast,_wSAxisRqTKeep}), .WR_DATA_VALID (_wSAxisRqTValid), .RD_DATA_READY (wSAxisRqTReady), .RST_IN (wRst), /*AUTOINST*/ // Inputs .CLK (CLK)); pipeline #( // Parameters .C_DEPTH (C_OUTPUT_STAGES), .C_WIDTH (C_PCI_DATA_WIDTH + 1 + (C_PCI_DATA_WIDTH/32) + `SIG_RQ_TUSER_W), .C_USE_MEMORY (0) /*AUTOINSTPARAM*/) output_inst ( // Outputs .WR_DATA_READY (wSAxisRqTReady), .RD_DATA ({S_AXIS_RQ_TDATA,S_AXIS_RQ_TLAST,S_AXIS_RQ_TKEEP,S_AXIS_RQ_TUSER}), .RD_DATA_VALID (S_AXIS_RQ_TVALID), // Inputs .WR_DATA ({wSAxisRqTData,wSAxisRqTLast,wSAxisRqTKeep,wSAxisRqTUser}), .WR_DATA_VALID (wSAxisRqTValid & ~wRstWaiting), .RD_DATA_READY (S_AXIS_RQ_TREADY), .RST_IN (wRst), /*AUTOINST*/ // Inputs .CLK (CLK)); endmodule // Local Variables: // verilog-library-directories:("." "../../../common/" "../../common/") // End:
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * 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. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // 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 REGENTS OF THE // UNIVERSITY OF CALIFORNIA 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. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: txr_engine_ultrascale.v // Version: 1.0 // Verilog Standard: Verilog-2001 // Description: The TXR Engine takes unformatted completions, formats // these packets into AXI-style packets. These packets must meet max-request, // max-payload, and payload termination requirements (see Read Completion // Boundary). The TXR Engine does not check these requirements during operation, // but may do so during simulation. // // This Engine is capable of operating at "line rate". // // Author: Dustin Richmond (@darichmond) //----------------------------------------------------------------------------- `include "trellis.vh" `include "ultrascale.vh" module txr_engine_ultrascale #(parameter C_PCI_DATA_WIDTH = 128, parameter C_PIPELINE_INPUT = 1, parameter C_PIPELINE_OUTPUT = 1, parameter C_DEPTH_PACKETS = 10, parameter C_MAX_PAYLOAD_DWORDS = 256) (// Interface: Clocks input CLK, // Interface: Resets input RST_BUS, // Replacement for generic RST_IN input RST_LOGIC, // Addition for RIFFA_RST output DONE_TXR_RST, // Interface: Configuration input [`SIG_CPLID_W-1:0] CONFIG_COMPLETER_ID, // Interface: RQ input S_AXIS_RQ_TREADY, output S_AXIS_RQ_TVALID, output S_AXIS_RQ_TLAST, output [C_PCI_DATA_WIDTH-1:0] S_AXIS_RQ_TDATA, output [(C_PCI_DATA_WIDTH/32)-1:0] S_AXIS_RQ_TKEEP, output [`SIG_RQ_TUSER_W-1:0] S_AXIS_RQ_TUSER, // Interface: TXR Engine input TXR_DATA_VALID, input [C_PCI_DATA_WIDTH-1:0] TXR_DATA, input TXR_DATA_START_FLAG, input [clog2s(C_PCI_DATA_WIDTH/32)-1:0] TXR_DATA_START_OFFSET, input TXR_DATA_END_FLAG, input [clog2s(C_PCI_DATA_WIDTH/32)-1:0] TXR_DATA_END_OFFSET, output TXR_DATA_READY, input TXR_META_VALID, input [`SIG_FBE_W-1:0] TXR_META_FDWBE, input [`SIG_LBE_W-1:0] TXR_META_LDWBE, input [`SIG_ADDR_W-1:0] TXR_META_ADDR, input [`SIG_LEN_W-1:0] TXR_META_LENGTH, input [`SIG_TAG_W-1:0] TXR_META_TAG, input [`SIG_TC_W-1:0] TXR_META_TC, input [`SIG_ATTR_W-1:0] TXR_META_ATTR, input [`SIG_TYPE_W-1:0] TXR_META_TYPE, input TXR_META_EP, output TXR_META_READY ); localparam C_VENDOR = "XILINX"; localparam C_DATA_WIDTH = C_PCI_DATA_WIDTH; localparam C_MAX_HDR_WIDTH = `UPKT_TXR_MAXHDR_W; localparam C_MAX_HDR_DWORDS = C_MAX_HDR_WIDTH/32; localparam C_MAX_ALIGN_DWORDS = 0; localparam C_MAX_NONPAY_DWORDS = C_MAX_HDR_DWORDS + C_MAX_ALIGN_DWORDS + 1; localparam C_MAX_PACKET_DWORDS = C_MAX_NONPAY_DWORDS + C_MAX_PAYLOAD_DWORDS; localparam C_PIPELINE_FORMATTER_INPUT = C_PIPELINE_INPUT; localparam C_PIPELINE_FORMATTER_OUTPUT = C_PIPELINE_OUTPUT; localparam C_FORMATTER_DELAY = C_PIPELINE_FORMATTER_OUTPUT + C_PIPELINE_FORMATTER_INPUT; localparam C_RST_COUNT = 10; /*AUTOWIRE*/ /*AUTOINPUT*/ ///*AUTOOUTPUT*/ wire wTxHdrReady; wire wTxHdrValid; wire [C_MAX_HDR_WIDTH-1:0] wTxHdr; wire [`SIG_NONPAY_W-1:0] wTxHdrNonpayLen; wire [`SIG_PACKETLEN_W-1:0] wTxHdrPacketLen; wire [`SIG_LEN_W-1:0] wTxHdrPayloadLen; wire wTxHdrNopayload; wire wTxDataReady; wire [C_PCI_DATA_WIDTH-1:0] wTxData; wire [clog2s(C_PCI_DATA_WIDTH/32)-1:0] wTxDataEndOffset; wire wTxDataStartFlag; wire [(C_PCI_DATA_WIDTH/32)-1:0] wTxDataEndFlags; wire [(C_PCI_DATA_WIDTH/32)-1:0] wTxDataWordValid; wire [(C_PCI_DATA_WIDTH/32)-1:0] wTxDataWordReady; wire [C_PCI_DATA_WIDTH-1:0] wTxrPkt; wire wTxrPktEndFlag; wire [clog2s(C_PCI_DATA_WIDTH/32)-1:0] wTxrPktEndOffset; wire wTxrPktStartFlag; wire [clog2s(C_PCI_DATA_WIDTH/32)-1:0] wTxrPktStartOffset; wire wTxrPktValid; wire wTxrPktReady; wire wTransDoneRst; wire wTransRstOut; wire wDoneEngRst; wire wRst; wire [C_RST_COUNT:0] wShiftRegRst; assign DONE_TXR_RST = wTransDoneRst & wDoneEngRst; assign wRst = wShiftRegRst[C_RST_COUNT-3]; assign wDoneEngRst = ~wShiftRegRst[C_RST_COUNT]; shiftreg #(// Parameters .C_DEPTH (C_RST_COUNT), .C_WIDTH (1), .C_VALUE (1) /*AUTOINSTPARAM*/) rst_shiftreg (// Outputs .RD_DATA (wShiftRegRst), // Inputs .RST_IN (RST_BUS), .WR_DATA (wTransRstOut), /*AUTOINST*/ // Inputs .CLK (CLK)); txr_formatter_ultrascale #(.C_PIPELINE_OUTPUT (C_PIPELINE_FORMATTER_OUTPUT), .C_PIPELINE_INPUT (C_PIPELINE_FORMATTER_INPUT), /*AUTOINSTPARAM*/ // Parameters .C_PCI_DATA_WIDTH (C_PCI_DATA_WIDTH), .C_MAX_HDR_WIDTH (C_MAX_HDR_WIDTH), .C_MAX_NONPAY_DWORDS (C_MAX_NONPAY_DWORDS), .C_MAX_PACKET_DWORDS (C_MAX_PACKET_DWORDS)) txr_formatter_inst (// Outputs .TX_HDR_VALID (wTxHdrValid), .TX_HDR (wTxHdr[C_MAX_HDR_WIDTH-1:0]), .TX_HDR_NOPAYLOAD (wTxHdrNopayload), .TX_HDR_PAYLOAD_LEN (wTxHdrPayloadLen[`SIG_LEN_W-1:0]), .TX_HDR_NONPAY_LEN (wTxHdrNonpayLen[`SIG_NONPAY_W-1:0]), .TX_HDR_PACKET_LEN (wTxHdrPacketLen[`SIG_PACKETLEN_W-1:0]), // Inputs .TX_HDR_READY (wTxHdrReady), .RST_IN (wRst), /*AUTOINST*/ // Outputs .TXR_META_READY (TXR_META_READY), // Inputs .CLK (CLK), .CONFIG_COMPLETER_ID (CONFIG_COMPLETER_ID[`SIG_CPLID_W-1:0]), .TXR_META_VALID (TXR_META_VALID), .TXR_META_FDWBE (TXR_META_FDWBE[`SIG_FBE_W-1:0]), .TXR_META_LDWBE (TXR_META_LDWBE[`SIG_LBE_W-1:0]), .TXR_META_ADDR (TXR_META_ADDR[`SIG_ADDR_W-1:0]), .TXR_META_LENGTH (TXR_META_LENGTH[`SIG_LEN_W-1:0]), .TXR_META_TAG (TXR_META_TAG[`SIG_TAG_W-1:0]), .TXR_META_TC (TXR_META_TC[`SIG_TC_W-1:0]), .TXR_META_ATTR (TXR_META_ATTR[`SIG_ATTR_W-1:0]), .TXR_META_TYPE (TXR_META_TYPE[`SIG_TYPE_W-1:0]), .TXR_META_EP (TXR_META_EP)); tx_engine #(.C_DATA_WIDTH (C_PCI_DATA_WIDTH), /*AUTOINSTPARAM*/ // Parameters .C_DEPTH_PACKETS (C_DEPTH_PACKETS), .C_PIPELINE_INPUT (C_PIPELINE_INPUT), .C_PIPELINE_OUTPUT (C_PIPELINE_OUTPUT), .C_FORMATTER_DELAY (C_FORMATTER_DELAY), .C_MAX_HDR_WIDTH (C_MAX_HDR_WIDTH), .C_MAX_PAYLOAD_DWORDS (C_MAX_PAYLOAD_DWORDS), .C_VENDOR (C_VENDOR)) txr_engine_inst (// Outputs .TX_HDR_READY (wTxHdrReady), .TX_DATA_READY (TXR_DATA_READY), .TX_PKT (wTxrPkt[C_DATA_WIDTH-1:0]), .TX_PKT_START_FLAG (wTxrPktStartFlag), .TX_PKT_START_OFFSET (wTxrPktStartOffset[clog2s(C_DATA_WIDTH/32)-1:0]), .TX_PKT_END_FLAG (wTxrPktEndFlag), .TX_PKT_END_OFFSET (wTxrPktEndOffset[clog2s(C_DATA_WIDTH/32)-1:0]), .TX_PKT_VALID (wTxrPktValid), // Inputs .TX_HDR_VALID (wTxHdrValid), .TX_HDR (wTxHdr[C_MAX_HDR_WIDTH-1:0]), .TX_HDR_NOPAYLOAD (wTxHdrNopayload), .TX_HDR_PAYLOAD_LEN (wTxHdrPayloadLen[`SIG_LEN_W-1:0]), .TX_HDR_NONPAY_LEN (wTxHdrNonpayLen[`SIG_NONPAY_W-1:0]), .TX_HDR_PACKET_LEN (wTxHdrPacketLen[`SIG_PACKETLEN_W-1:0]), .TX_DATA_VALID (TXR_DATA_VALID), .TX_DATA (TXR_DATA[C_DATA_WIDTH-1:0]), .TX_DATA_START_FLAG (TXR_DATA_START_FLAG), .TX_DATA_START_OFFSET (TXR_DATA_START_OFFSET[clog2s(C_DATA_WIDTH/32)-1:0]), .TX_DATA_END_FLAG (TXR_DATA_END_FLAG), .TX_DATA_END_OFFSET (TXR_DATA_END_OFFSET[clog2s(C_DATA_WIDTH/32)-1:0]), .TX_PKT_READY (wTxrPktReady), .RST_IN (wRst),// TODO: /*AUTOINST*/ // Inputs .CLK (CLK)); txr_translation_layer #(/*AUTOINSTPARAM*/ // Parameters .C_PCI_DATA_WIDTH (C_PCI_DATA_WIDTH), .C_PIPELINE_INPUT (C_PIPELINE_INPUT), .C_RST_COUNT (C_RST_COUNT)) txr_trans_inst (// Outputs .TXR_PKT_READY (wTxrPktReady), .DONE_RST (wTransDoneRst), .RST_OUT (wTransRstOut), // Inputs .TXR_PKT (wTxrPkt), .TXR_PKT_VALID (wTxrPktValid), .TXR_PKT_START_FLAG (wTxrPktStartFlag), .TXR_PKT_START_OFFSET (wTxrPktStartOffset), .TXR_PKT_END_FLAG (wTxrPktEndFlag), .TXR_PKT_END_OFFSET (wTxrPktEndOffset), /*AUTOINST*/ // Outputs .S_AXIS_RQ_TVALID (S_AXIS_RQ_TVALID), .S_AXIS_RQ_TLAST (S_AXIS_RQ_TLAST), .S_AXIS_RQ_TDATA (S_AXIS_RQ_TDATA[C_PCI_DATA_WIDTH-1:0]), .S_AXIS_RQ_TKEEP (S_AXIS_RQ_TKEEP[(C_PCI_DATA_WIDTH/32)-1:0]), .S_AXIS_RQ_TUSER (S_AXIS_RQ_TUSER[`SIG_RQ_TUSER_W-1:0]), // Inputs .CLK (CLK), .RST_BUS (RST_BUS), .RST_LOGIC (RST_LOGIC), .S_AXIS_RQ_TREADY (S_AXIS_RQ_TREADY)); endmodule // txr_engine_ultrascale module txr_formatter_ultrascale #( parameter C_PCI_DATA_WIDTH = 128, parameter C_PIPELINE_INPUT = 1, parameter C_PIPELINE_OUTPUT = 1, parameter C_MAX_HDR_WIDTH = `UPKT_TXR_MAXHDR_W, parameter C_MAX_NONPAY_DWORDS = 5, parameter C_MAX_PACKET_DWORDS = 10 ) ( // Interface: Clocks input CLK, // Interface: Resets input RST_IN, // Interface: Configuration input [`SIG_CPLID_W-1:0] CONFIG_COMPLETER_ID, // Interface: TXR input TXR_META_VALID, input [`SIG_FBE_W-1:0] TXR_META_FDWBE, input [`SIG_LBE_W-1:0] TXR_META_LDWBE, input [`SIG_ADDR_W-1:0] TXR_META_ADDR, input [`SIG_LEN_W-1:0] TXR_META_LENGTH, input [`SIG_TAG_W-1:0] TXR_META_TAG, input [`SIG_TC_W-1:0] TXR_META_TC, input [`SIG_ATTR_W-1:0] TXR_META_ATTR, input [`SIG_TYPE_W-1:0] TXR_META_TYPE, input TXR_META_EP, output TXR_META_READY, // Interface: TX HDR output TX_HDR_VALID, output [C_MAX_HDR_WIDTH-1:0] TX_HDR, output [`SIG_LEN_W-1:0] TX_HDR_PAYLOAD_LEN, output [`SIG_NONPAY_W-1:0] TX_HDR_NONPAY_LEN, output [`SIG_PACKETLEN_W-1:0] TX_HDR_PACKET_LEN, output TX_HDR_NOPAYLOAD, input TX_HDR_READY ); wire wHdrNoPayload; wire [`UPKT_TXR_MAXHDR_W-1:0] wHdr; wire wTxHdrReady; wire wTxHdrValid; wire [`UPKT_TXR_MAXHDR_W-1:0] wTxHdr; wire [`SIG_NONPAY_W-1:0] wTxHdrNonpayLen; wire [`SIG_PACKETLEN_W-1:0] wTxHdrPacketLen; wire [`SIG_LEN_W-1:0] wTxHdrPayloadLen; wire wTxHdrNopayload; wire [`SIG_TYPE_W-1:0] wTxHdrType; // Generic Header Fields assign wHdr[`UPKT_TXR_ATYPE_R] = `UPKT_TXR_ATYPE_W'd0; assign wHdr[`UPKT_TXR_ADDR_R] = TXR_META_ADDR[63:2]; assign wHdr[`UPKT_TXR_LENGTH_R] = {1'b0,TXR_META_LENGTH}; assign wHdr[`UPKT_TXR_EP_R] = TXR_META_EP; `ifdef BE_HACK assign wHdr[`UPKT_TXR_FBE_R] = TXR_META_FDWBE; assign wHdr[`UPKT_TXR_LBE_R] = TXR_META_LDWBE; assign wHdr[`UPKT_TXR_RSVD0_R] = 0; `else assign wHdr[`UPKT_TXR_REQID_R] = CONFIG_COMPLETER_ID; `endif //assign wHdr[`UPKT_TXR_REQID_R] = `UPKT_TXR_REQID_W'd0; assign wHdr[`UPKT_TXR_TAG_R] = TXR_META_TAG; assign wHdr[`UPKT_TXR_CPLID_R] = `UPKT_TXR_CPLID_W'd0; assign wHdr[`UPKT_TXR_REQIDEN_R] = 0; assign wHdr[`UPKT_TXR_TC_R] = TXR_META_TC; assign wHdr[`UPKT_TXR_ATTR_R] = TXR_META_ATTR; assign wHdr[`UPKT_TXR_TD_R] = `UPKT_TXR_TD_W'd0; assign wTxHdr[`UPKT_TXR_TYPE_R] = trellis_to_upkt_type(wTxHdrType); assign wTxHdrNopayload = ~wTxHdrType[`TRLS_TYPE_PAY_I]; assign wTxHdrNonpayLen = 4; assign wTxHdrPayloadLen = wTxHdrNopayload ? 0 : wTxHdr[`UPKT_TXR_LENGTH_R]; assign wTxHdrPacketLen = wTxHdrNonpayLen + wTxHdrPayloadLen; pipeline #( // Parameters .C_DEPTH (C_PIPELINE_INPUT?1:0), .C_WIDTH (`UPKT_TXR_MAXHDR_W-1), .C_USE_MEMORY (0) /*AUTOINSTPARAM*/) input_inst ( // Outputs .WR_DATA_READY (TXR_META_READY), .RD_DATA ({wTxHdr[`UPKT_TXR_MAXHDR_W-1:(`UPKT_TXR_TYPE_I + `UPKT_TXR_TYPE_W)], wTxHdr[`UPKT_TXR_TYPE_I-1:0], wTxHdrType}), .RD_DATA_VALID (wTxHdrValid), // Inputs .WR_DATA ({wHdr[`UPKT_TXR_MAXHDR_W-1:(`UPKT_TXR_TYPE_I + `UPKT_TXR_TYPE_W)], wHdr[`UPKT_TXR_TYPE_I-1:0], TXR_META_TYPE}), .WR_DATA_VALID (TXR_META_VALID), .RD_DATA_READY (wTxHdrReady), /*AUTOINST*/ // Inputs .CLK (CLK), .RST_IN (RST_IN)); pipeline #( // Parameters .C_DEPTH (C_PIPELINE_OUTPUT?1:0), .C_WIDTH (`UPKT_TXR_MAXHDR_W + 1 + `SIG_PACKETLEN_W + `SIG_LEN_W + `SIG_NONPAY_W), .C_USE_MEMORY (0) /*AUTOINSTPARAM*/) output_inst ( // Outputs .WR_DATA_READY (wTxHdrReady), .RD_DATA ({TX_HDR,TX_HDR_NOPAYLOAD,TX_HDR_PACKET_LEN,TX_HDR_PAYLOAD_LEN,TX_HDR_NONPAY_LEN}), .RD_DATA_VALID (TX_HDR_VALID), // Inputs .WR_DATA ({wTxHdr,wTxHdrNopayload,wTxHdrPacketLen,wTxHdrPayloadLen,wTxHdrNonpayLen}), .WR_DATA_VALID (wTxHdrValid), .RD_DATA_READY (TX_HDR_READY), /*AUTOINST*/ // Inputs .CLK (CLK), .RST_IN (RST_IN)); endmodule module txr_translation_layer #(parameter C_PCI_DATA_WIDTH = 10'd128, parameter C_PIPELINE_INPUT = 1, parameter C_RST_COUNT = 1) (// Interface: Clocks input CLK, // Interface: Resets input RST_BUS, // Replacement for generic RST_IN input RST_LOGIC, // Addition for RIFFA_RST output RST_OUT, output DONE_RST, // Interface: TXR Classic output TXR_PKT_READY, input [C_PCI_DATA_WIDTH-1:0] TXR_PKT, input TXR_PKT_VALID, input TXR_PKT_START_FLAG, input [clog2s(C_PCI_DATA_WIDTH/32)-1:0] TXR_PKT_START_OFFSET, input TXR_PKT_END_FLAG, input [clog2s(C_PCI_DATA_WIDTH/32)-1:0] TXR_PKT_END_OFFSET, // Interface: RQ input S_AXIS_RQ_TREADY, output S_AXIS_RQ_TVALID, output S_AXIS_RQ_TLAST, output [C_PCI_DATA_WIDTH-1:0] S_AXIS_RQ_TDATA, output [(C_PCI_DATA_WIDTH/32)-1:0] S_AXIS_RQ_TKEEP, output [`SIG_RQ_TUSER_W-1:0] S_AXIS_RQ_TUSER); localparam C_INPUT_STAGES = C_PIPELINE_INPUT != 0? 1:0; localparam C_OUTPUT_STAGES = 1; wire wTxrPktReady; wire [C_PCI_DATA_WIDTH-1:0] wTxrPkt; wire wTxrPktValid; wire wTxrPktStartFlag; wire [clog2s(C_PCI_DATA_WIDTH/32)-1:0] wTxrPktStartOffset; wire wTxrPktEndFlag; wire [clog2s(C_PCI_DATA_WIDTH/32)-1:0] wTxrPktEndOffset; wire wSAxisRqTReady; wire wSAxisRqTValid; wire wSAxisRqTLast; wire [C_PCI_DATA_WIDTH-1:0] wSAxisRqTData; wire [(C_PCI_DATA_WIDTH/32)-1:0] wSAxisRqTKeep; wire [`SIG_RQ_TUSER_W-1:0] wSAxisRqTUser; wire _wSAxisRqTReady; wire _wSAxisRqTValid; wire _wSAxisRqTLast; wire [C_PCI_DATA_WIDTH-1:0] _wSAxisRqTData; wire [(C_PCI_DATA_WIDTH/32)-1:0] _wSAxisRqTKeep; wire wRst; wire wRstWaiting; /*ASSIGN TXR -> RQ*/ assign wTxrPktReady = _wSAxisRqTReady; assign _wSAxisRqTValid = wTxrPktValid; assign _wSAxisRqTLast = wTxrPktEndFlag; assign _wSAxisRqTData = wTxrPkt; // BE Hack assign wSAxisRqTUser[3:0] = wTxrPkt[(`UPKT_TXR_FBE_I % C_PCI_DATA_WIDTH) +: `UPKT_TXR_FBE_W]; assign wSAxisRqTUser[7:4] = wTxrPkt[(`UPKT_TXR_LBE_I % C_PCI_DATA_WIDTH) +: `UPKT_TXR_LBE_W]; assign wSAxisRqTUser[`SIG_RQ_TUSER_W-1:8] = 0; assign RST_OUT = wRst; // This reset controller assumes there is always an output stage reset_controller #(/*AUTOINSTPARAM*/ // Parameters .C_RST_COUNT (C_RST_COUNT)) rc (// Outputs .RST_OUT (wRst), .WAITING_RESET (wRstWaiting), // Inputs .RST_IN (RST_BUS), .SIGNAL_RST (RST_LOGIC), .WAIT_RST (S_AXIS_RQ_TVALID), .NEXT_CYC_RST (S_AXIS_RQ_TREADY & S_AXIS_RQ_TLAST), /*AUTOINST*/ // Outputs .DONE_RST (DONE_RST), // Inputs .CLK (CLK)); pipeline #(// Parameters .C_DEPTH (C_INPUT_STAGES), .C_WIDTH (C_PCI_DATA_WIDTH + 2*(1+clog2s(C_PCI_DATA_WIDTH/32))), .C_USE_MEMORY (0) /*AUTOINSTPARAM*/) input_inst ( // Outputs .WR_DATA_READY (TXR_PKT_READY), .RD_DATA ({wTxrPkt,wTxrPktStartFlag,wTxrPktStartOffset,wTxrPktEndFlag,wTxrPktEndOffset}), .RD_DATA_VALID (wTxrPktValid), // Inputs .WR_DATA ({TXR_PKT,TXR_PKT_START_FLAG,TXR_PKT_START_OFFSET, TXR_PKT_END_FLAG,TXR_PKT_END_OFFSET}), .WR_DATA_VALID (TXR_PKT_VALID), .RD_DATA_READY (wTxrPktReady), .RST_IN (wRst), /*AUTOINST*/ // Inputs .CLK (CLK)); offset_to_mask #( // Parameters .C_MASK_SWAP (0), .C_MASK_WIDTH (C_PCI_DATA_WIDTH/32) /*AUTOINSTPARAM*/) otom_inst ( // Outputs .MASK (_wSAxisRqTKeep), // Inputs .OFFSET_ENABLE (wTxrPktEndFlag), .OFFSET (wTxrPktEndOffset) /*AUTOINST*/); pipeline #( // Parameters .C_DEPTH (64/C_PCI_DATA_WIDTH), .C_WIDTH (C_PCI_DATA_WIDTH + 1 + (C_PCI_DATA_WIDTH/32)), .C_USE_MEMORY (0) /*AUTOINSTPARAM*/) fbe_hack_inst ( // Outputs .WR_DATA_READY (_wSAxisRqTReady), .RD_DATA ({wSAxisRqTData,wSAxisRqTLast,wSAxisRqTKeep}), .RD_DATA_VALID (wSAxisRqTValid), // Inputs .WR_DATA ({_wSAxisRqTData,_wSAxisRqTLast,_wSAxisRqTKeep}), .WR_DATA_VALID (_wSAxisRqTValid), .RD_DATA_READY (wSAxisRqTReady), .RST_IN (wRst), /*AUTOINST*/ // Inputs .CLK (CLK)); pipeline #( // Parameters .C_DEPTH (C_OUTPUT_STAGES), .C_WIDTH (C_PCI_DATA_WIDTH + 1 + (C_PCI_DATA_WIDTH/32) + `SIG_RQ_TUSER_W), .C_USE_MEMORY (0) /*AUTOINSTPARAM*/) output_inst ( // Outputs .WR_DATA_READY (wSAxisRqTReady), .RD_DATA ({S_AXIS_RQ_TDATA,S_AXIS_RQ_TLAST,S_AXIS_RQ_TKEEP,S_AXIS_RQ_TUSER}), .RD_DATA_VALID (S_AXIS_RQ_TVALID), // Inputs .WR_DATA ({wSAxisRqTData,wSAxisRqTLast,wSAxisRqTKeep,wSAxisRqTUser}), .WR_DATA_VALID (wSAxisRqTValid & ~wRstWaiting), .RD_DATA_READY (S_AXIS_RQ_TREADY), .RST_IN (wRst), /*AUTOINST*/ // Inputs .CLK (CLK)); endmodule // Local Variables: // verilog-library-directories:("." "../../../common/" "../../common/") // End:
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * 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. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // 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 REGENTS OF THE // UNIVERSITY OF CALIFORNIA 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. // ---------------------------------------------------------------------- /* Filename: translation_layer.v Version: 1.0 Verilog Standard: Verilog-2001 Description: The translation layer provides a uniform interface for all classic PCIe interfaces, such as all Altera devices, and all Xilinx devices (pre VC709). Notes: Any modifications to this file should meet the conditions set forth in the "Trellis Style Guide" Author: Dustin Richmond (@darichmond) Co-Authors: */ `include "trellis.vh" // Defines the user-facing signal widths. `include "xilinx.vh" module translation_xilinx #( parameter C_PCI_DATA_WIDTH = 256 ) ( input CLK, input RST_IN, // Interface: Xilinx RX input [C_PCI_DATA_WIDTH-1:0] M_AXIS_RX_TDATA, input [(C_PCI_DATA_WIDTH/8)-1:0] M_AXIS_RX_TKEEP, input M_AXIS_RX_TLAST, input M_AXIS_RX_TVALID, output M_AXIS_RX_TREADY, input [`SIG_XIL_RX_TUSER_W-1:0] M_AXIS_RX_TUSER, output RX_NP_OK, output RX_NP_REQ, // Interface: Xilinx TX output [C_PCI_DATA_WIDTH-1:0] S_AXIS_TX_TDATA, output [(C_PCI_DATA_WIDTH/8)-1:0] S_AXIS_TX_TKEEP, output S_AXIS_TX_TLAST, output S_AXIS_TX_TVALID, input S_AXIS_TX_TREADY, output [`SIG_XIL_TX_TUSER_W-1:0] S_AXIS_TX_TUSER, output TX_CFG_GNT, // Interface: Xilinx Configuration input [`SIG_BUSID_W-1:0] CFG_BUS_NUMBER, input [`SIG_DEVID_W-1:0] CFG_DEVICE_NUMBER, input [`SIG_FNID_W-1:0] CFG_FUNCTION_NUMBER, input [`SIG_CFGREG_W-1:0] CFG_COMMAND, input [`SIG_CFGREG_W-1:0] CFG_DCOMMAND, input [`SIG_CFGREG_W-1:0] CFG_LSTATUS, input [`SIG_CFGREG_W-1:0] CFG_LCOMMAND, // Interface: Xilinx Flow Control input [`SIG_FC_CPLD_W-1:0] FC_CPLD, input [`SIG_FC_CPLH_W-1:0] FC_CPLH, output [`SIG_FC_SEL_W-1:0] FC_SEL, // Interface: Xilinx Interrupt input CFG_INTERRUPT_MSIEN, input CFG_INTERRUPT_RDY, output CFG_INTERRUPT, // Interface: RX Classic output [C_PCI_DATA_WIDTH-1:0] RX_TLP, output RX_TLP_VALID, output RX_TLP_START_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] RX_TLP_START_OFFSET, output RX_TLP_END_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] RX_TLP_END_OFFSET, output [`SIG_BARDECODE_W-1:0] RX_TLP_BAR_DECODE, input RX_TLP_READY, // Interface: TX Classic output TX_TLP_READY, input [C_PCI_DATA_WIDTH-1:0] TX_TLP, input TX_TLP_VALID, input TX_TLP_START_FLAG, input [clog2s(C_PCI_DATA_WIDTH/32)-1:0] TX_TLP_START_OFFSET, input TX_TLP_END_FLAG, input [clog2s(C_PCI_DATA_WIDTH/32)-1:0] TX_TLP_END_OFFSET, // Interface: Configuration output [`SIG_CPLID_W-1:0] CONFIG_COMPLETER_ID, output CONFIG_BUS_MASTER_ENABLE, output [`SIG_LINKWIDTH_W-1:0] CONFIG_LINK_WIDTH, output [`SIG_LINKRATE_W-1:0] CONFIG_LINK_RATE, output [`SIG_MAXREAD_W-1:0] CONFIG_MAX_READ_REQUEST_SIZE, output [`SIG_MAXPAYLOAD_W-1:0] CONFIG_MAX_PAYLOAD_SIZE, output CONFIG_INTERRUPT_MSIENABLE, output CONFIG_CPL_BOUNDARY_SEL, // Interface: Flow Control output [`SIG_FC_CPLD_W-1:0] CONFIG_MAX_CPL_DATA, output [`SIG_FC_CPLH_W-1:0] CONFIG_MAX_CPL_HDR, // Interface: Interrupt output INTR_MSI_RDY, // High when interrupt is able to be sent input INTR_MSI_REQUEST // High to request interrupt ); /* Notes on the Configuration Interface: Link Width (cfg_lstatus[9:4]): 000001=x1, 000010=x2, 000100=x4, 001000=x8, 001100=x12, 010000=x16 Link Rate (cfg_lstatus[3:0]): 0001=2.5GT/s, 0010=5.0GT/s, 0011=8.0GT/s Max Read Request Size (cfg_dcommand[14:12]): 000=128B, 001=256B, 010=512B, 011=1024B, 100=2048B, 101=4096B Max Payload Size (cfg_dcommand[7:5]): 000=128B, 001=256B, 010=512B, 011=1024B Bus Master Enable (cfg_command[2]): 1=Enabled, 0=Disabled Read Completion Boundary (cfg_lcommand[3]): 0=64 bytes, 1=128 bytes MSI Enable (cfg_msicsr[0]): 1=Enabled, 0=Disabled Notes on the Flow Control Interface: FC_CPLD (Xilinx) Receive credit limit for data FC_CPLH (Xilinx) Receive credit limit for headers FC_SEL (Xilinx Only) Selects the correct output on the FC_* signals Notes on the TX Interface: TX_CFG_GNT (Xilinx): 1=Always allow core to transmit internally generated TLPs Notes on the RX Interface: RX_NP_OK (Xilinx): 1=Always allow non posted transactions */ /*AUTOWIRE*/ reg rRxTlpValid; reg rRxTlpEndFlag; // Rx Interface (From PCIe Core) assign RX_TLP = M_AXIS_RX_TDATA; assign RX_TLP_VALID = M_AXIS_RX_TVALID; // Rx Interface (To PCIe Core) assign M_AXIS_RX_TREADY = RX_TLP_READY; // TX Interface (From PCIe Core) assign TX_TLP_READY = S_AXIS_TX_TREADY; // TX Interface (TO PCIe Core) assign S_AXIS_TX_TDATA = TX_TLP; assign S_AXIS_TX_TVALID = TX_TLP_VALID; assign S_AXIS_TX_TLAST = TX_TLP_END_FLAG; // Configuration Interface assign CONFIG_COMPLETER_ID = {CFG_BUS_NUMBER,CFG_DEVICE_NUMBER,CFG_FUNCTION_NUMBER}; assign CONFIG_BUS_MASTER_ENABLE = CFG_COMMAND[`CFG_COMMAND_BUSMSTR_R]; assign CONFIG_LINK_WIDTH = CFG_LSTATUS[`CFG_LSTATUS_LWIDTH_R]; assign CONFIG_LINK_RATE = CFG_LSTATUS[`CFG_LSTATUS_LRATE_R]; assign CONFIG_MAX_READ_REQUEST_SIZE = CFG_DCOMMAND[`CFG_DCOMMAND_MAXREQ_R]; assign CONFIG_MAX_PAYLOAD_SIZE = CFG_DCOMMAND[`CFG_DCOMMAND_MAXPAY_R]; assign CONFIG_INTERRUPT_MSIENABLE = CFG_INTERRUPT_MSIEN; assign CONFIG_CPL_BOUNDARY_SEL = CFG_LCOMMAND[`CFG_LCOMMAND_RCB_R]; assign CONFIG_MAX_CPL_DATA = FC_CPLD; assign CONFIG_MAX_CPL_HDR = FC_CPLH; assign FC_SEL = `SIG_FC_SEL_RX_MAXALLOC_V; assign RX_NP_OK = 1'b1; assign RX_NP_REQ = 1'b1; assign TX_CFG_GNT = 1'b1; // Interrupt interface assign CFG_INTERRUPT = INTR_MSI_REQUEST; assign INTR_MSI_RDY = CFG_INTERRUPT_RDY; generate if (C_PCI_DATA_WIDTH == 9'd32) begin : gen_xilinx_32 assign RX_TLP_START_FLAG = ~rRxTlpValid | rRxTlpEndFlag; assign RX_TLP_START_OFFSET = {clog2s(C_PCI_DATA_WIDTH/32){1'b0}}; assign RX_TLP_END_OFFSET = 0; assign RX_TLP_END_FLAG = M_AXIS_RX_TLAST; assign S_AXIS_TX_TKEEP = 4'hF; end else if (C_PCI_DATA_WIDTH == 9'd64) begin : gen_xilinx_64 assign RX_TLP_START_FLAG = ~rRxTlpValid | rRxTlpEndFlag; assign RX_TLP_START_OFFSET = {clog2s(C_PCI_DATA_WIDTH/32){1'b0}}; assign RX_TLP_END_OFFSET = M_AXIS_RX_TKEEP[4]; assign RX_TLP_END_FLAG = M_AXIS_RX_TLAST; assign S_AXIS_TX_TKEEP = {{4{TX_TLP_END_OFFSET | ~TX_TLP_END_FLAG}},4'hF}; end else if (C_PCI_DATA_WIDTH == 9'd128) begin : gen_xilinx_128 assign RX_TLP_END_OFFSET = M_AXIS_RX_TUSER[20:19]; assign RX_TLP_END_FLAG = M_AXIS_RX_TUSER[21]; assign RX_TLP_START_FLAG = M_AXIS_RX_TUSER[14]; assign RX_TLP_START_OFFSET = M_AXIS_RX_TUSER[13:12]; assign S_AXIS_TX_TKEEP = {{4{~TX_TLP_END_FLAG | (TX_TLP_END_OFFSET == 2'b11)}}, {4{~TX_TLP_END_FLAG | (TX_TLP_END_OFFSET >= 2'b10)}}, {4{~TX_TLP_END_FLAG | (TX_TLP_END_OFFSET >= 2'b01)}}, {4{1'b1}}};// TODO: More efficient if we use masks... end else if (C_PCI_DATA_WIDTH == 9'd256) begin : x256 // Not possible... end endgenerate always @(posedge CLK) begin rRxTlpValid <= RX_TLP_VALID; rRxTlpEndFlag <= RX_TLP_END_FLAG; end endmodule // translation_layer
(** * Hoare: Hoare Logic, Part I *) Require Export Imp. (** In the past couple of chapters, we've begun applying the mathematical tools developed in the first part of the course to studying the theory of a small programming language, Imp. - We defined a type of _abstract syntax trees_ for Imp, together with an _evaluation relation_ (a partial function on states) that specifies the _operational semantics_ of programs. The language we defined, though small, captures some of the key features of full-blown languages like C, C++, and Java, including the fundamental notion of mutable state and some common control structures. - We proved a number of _metatheoretic properties_ -- "meta" in the sense that they are properties of the language as a whole, rather than properties of particular programs in the language. These included: - determinism of evaluation - equivalence of some different ways of writing down the definitions (e.g. functional and relational definitions of arithmetic expression evaluation) - guaranteed termination of certain classes of programs - correctness (in the sense of preserving meaning) of a number of useful program transformations - behavioral equivalence of programs (in the [Equiv] chapter). If we stopped here, we would already have something useful: a set of tools for defining and discussing programming languages and language features that are mathematically precise, flexible, and easy to work with, applied to a set of key properties. All of these properties are things that language designers, compiler writers, and users might care about knowing. Indeed, many of them are so fundamental to our understanding of the programming languages we deal with that we might not consciously recognize them as "theorems." But properties that seem intuitively obvious can sometimes be quite subtle (in some cases, even subtly wrong!). We'll return to the theme of metatheoretic properties of whole languages later in the course when we discuss _types_ and _type soundness_. In this chapter, though, we'll turn to a different set of issues. Our goal is to see how to carry out some simple examples of _program verification_ -- i.e., using the precise definition of Imp to prove formally that particular programs satisfy particular specifications of their behavior. We'll develop a reasoning system called _Floyd-Hoare Logic_ -- often shortened to just _Hoare Logic_ -- in which each of the syntactic constructs of Imp is equipped with a single, generic "proof rule" that can be used to reason compositionally about the correctness of programs involving this construct. Hoare Logic originates in the 1960s, and it continues to be the subject of intensive research right up to the present day. It lies at the core of a multitude of tools that are being used in academia and industry to specify and verify real software systems. *) (* ####################################################### *) (** * Hoare Logic *) (** Hoare Logic combines two beautiful ideas: a natural way of writing down _specifications_ of programs, and a _compositional proof technique_ for proving that programs are correct with respect to such specifications -- where by "compositional" we mean that the structure of proofs directly mirrors the structure of the programs that they are about. *) (* ####################################################### *) (** ** Assertions *) (** To talk about specifications of programs, the first thing we need is a way of making _assertions_ about properties that hold at particular points during a program's execution -- i.e., claims about the current state of the memory when program execution reaches that point. Formally, an assertion is just a family of propositions indexed by a [state]. *) Definition Assertion := state -> Prop. (** **** Exercise: 1 star, optional (assertions) *) Module ExAssertions. (** Paraphrase the following assertions in English. *) Definition as1 : Assertion := fun st => st X = 3. Definition as2 : Assertion := fun st => st X <= st Y. Definition as3 : Assertion := fun st => st X = 3 \/ st X <= st Y. Definition as4 : Assertion := fun st => st Z * st Z <= st X /\ ~ (((S (st Z)) * (S (st Z))) <= st X). Definition as5 : Assertion := fun st => True. Definition as6 : Assertion := fun st => False. (* FILL IN HERE *) End ExAssertions. (** [] *) (* ####################################################### *) (** ** Notation for Assertions *) (** This way of writing assertions can be a little bit heavy, for two reasons: (1) every single assertion that we ever write is going to begin with [fun st => ]; and (2) this state [st] is the only one that we ever use to look up variables (we will never need to talk about two different memory states at the same time). For discussing examples informally, we'll adopt some simplifying conventions: we'll drop the initial [fun st =>], and we'll write just [X] to mean [st X]. Thus, instead of writing *) (** fun st => (st Z) * (st Z) <= m /\ ~ ((S (st Z)) * (S (st Z)) <= m) we'll write just Z * Z <= m /\ ~((S Z) * (S Z) <= m). *) (** Given two assertions [P] and [Q], we say that [P] _implies_ [Q], written [P ->> Q] (in ASCII, [P -][>][> Q]), if, whenever [P] holds in some state [st], [Q] also holds. *) Definition assert_implies (P Q : Assertion) : Prop := forall st, P st -> Q st. Notation "P ->> Q" := (assert_implies P Q) (at level 80) : hoare_spec_scope. Open Scope hoare_spec_scope. (** We'll also have occasion to use the "iff" variant of implication between assertions: *) Notation "P <<->> Q" := (P ->> Q /\ Q ->> P) (at level 80) : hoare_spec_scope. (* ####################################################### *) (** ** Hoare Triples *) (** Next, we need a way of making formal claims about the behavior of commands. *) (** Since the behavior of a command is to transform one state to another, it is natural to express claims about commands in terms of assertions that are true before and after the command executes: - "If command [c] is started in a state satisfying assertion [P], and if [c] eventually terminates in some final state, then this final state will satisfy the assertion [Q]." Such a claim is called a _Hoare Triple_. The property [P] is called the _precondition_ of [c], while [Q] is the _postcondition_. Formally: *) Definition hoare_triple (P:Assertion) (c:com) (Q:Assertion) : Prop := forall st st', c / st || st' -> P st -> Q st'. (** Since we'll be working a lot with Hoare triples, it's useful to have a compact notation: {{P}} c {{Q}}. *) (** (The traditional notation is [{P} c {Q}], but single braces are already used for other things in Coq.) *) Notation "{{ P }} c {{ Q }}" := (hoare_triple P c Q) (at level 90, c at next level) : hoare_spec_scope. (** (The [hoare_spec_scope] annotation here tells Coq that this notation is not global but is intended to be used in particular contexts. The [Open Scope] tells Coq that this file is one such context.) *) (** **** Exercise: 1 star, optional (triples) *) (** Paraphrase the following Hoare triples in English. 1) {{True}} c {{X = 5}} 2) {{X = m}} c {{X = m + 5)}} 3) {{X <= Y}} c {{Y <= X}} 4) {{True}} c {{False}} 5) {{X = m}} c {{Y = real_fact m}}. 6) {{True}} c {{(Z * Z) <= m /\ ~ (((S Z) * (S Z)) <= m)}} *) (** [] *) (** **** Exercise: 1 star, optional (valid_triples) *) (** Which of the following Hoare triples are _valid_ -- i.e., the claimed relation between [P], [c], and [Q] is true? 1) {{True}} X ::= 5 {{X = 5}} 2) {{X = 2}} X ::= X + 1 {{X = 3}} 3) {{True}} X ::= 5; Y ::= 0 {{X = 5}} 4) {{X = 2 /\ X = 3}} X ::= 5 {{X = 0}} 5) {{True}} SKIP {{False}} 6) {{False}} SKIP {{True}} 7) {{True}} WHILE True DO SKIP END {{False}} 8) {{X = 0}} WHILE X == 0 DO X ::= X + 1 END {{X = 1}} 9) {{X = 1}} WHILE X <> 0 DO X ::= X + 1 END {{X = 100}} *) (* FILL IN HERE *) (** [] *) (** (Note that we're using informal mathematical notations for expressions inside of commands, for readability, rather than their formal [aexp] and [bexp] encodings. We'll continue doing so throughout the chapter.) *) (** To get us warmed up for what's coming, here are two simple facts about Hoare triples. *) Theorem hoare_post_true : forall (P Q : Assertion) c, (forall st, Q st) -> {{P}} c {{Q}}. Proof. intros P Q c H. unfold hoare_triple. intros st st' Heval HP. apply H. Qed. Theorem hoare_pre_false : forall (P Q : Assertion) c, (forall st, ~(P st)) -> {{P}} c {{Q}}. Proof. intros P Q c H. unfold hoare_triple. intros st st' Heval HP. unfold not in H. apply H in HP. inversion HP. Qed. (* ####################################################### *) (** ** Proof Rules *) (** The goal of Hoare logic is to provide a _compositional_ method for proving the validity of Hoare triples. That is, the structure of a program's correctness proof should mirror the structure of the program itself. To this end, in the sections below, we'll introduce one rule for reasoning about each of the different syntactic forms of commands in Imp -- one for assignment, one for sequencing, one for conditionals, etc. -- plus a couple of "structural" rules that are useful for gluing things together. We will prove programs correct using these proof rules, without ever unfolding the definition of [hoare_triple]. *) (* ####################################################### *) (** *** Assignment *) (** The rule for assignment is the most fundamental of the Hoare logic proof rules. Here's how it works. Consider this (valid) Hoare triple: {{ Y = 1 }} X ::= Y {{ X = 1 }} In English: if we start out in a state where the value of [Y] is [1] and we assign [Y] to [X], then we'll finish in a state where [X] is [1]. That is, the property of being equal to [1] gets transferred from [Y] to [X]. Similarly, in {{ Y + Z = 1 }} X ::= Y + Z {{ X = 1 }} the same property (being equal to one) gets transferred to [X] from the expression [Y + Z] on the right-hand side of the assignment. More generally, if [a] is _any_ arithmetic expression, then {{ a = 1 }} X ::= a {{ X = 1 }} is a valid Hoare triple. This can be made even more general. To conclude that an _arbitrary_ property [Q] holds after [X ::= a], we need to assume that [Q] holds before [X ::= a], but _with all occurrences of_ [X] replaced by [a] in [Q]. This leads to the Hoare rule for assignment {{ Q [X |-> a] }} X ::= a {{ Q }} where "[Q [X |-> a]]" is pronounced "[Q] where [a] is substituted for [X]". For example, these are valid applications of the assignment rule: {{ (X <= 5) [X |-> X + 1] i.e., X + 1 <= 5 }} X ::= X + 1 {{ X <= 5 }} {{ (X = 3) [X |-> 3] i.e., 3 = 3}} X ::= 3 {{ X = 3 }} {{ (0 <= X /\ X <= 5) [X |-> 3] i.e., (0 <= 3 /\ 3 <= 5)}} X ::= 3 {{ 0 <= X /\ X <= 5 }} *) (** To formalize the rule, we must first formalize the idea of "substituting an expression for an Imp variable in an assertion." That is, given a proposition [P], a variable [X], and an arithmetic expression [a], we want to derive another proposition [P'] that is just the same as [P] except that, wherever [P] mentions [X], [P'] should instead mention [a]. Since [P] is an arbitrary Coq proposition, we can't directly "edit" its text. Instead, we can achieve the effect we want by evaluating [P] in an updated state: *) Definition assn_sub X a P : Assertion := fun (st : state) => P (update st X (aeval st a)). Notation "P [ X |-> a ]" := (assn_sub X a P) (at level 10). (** That is, [P [X |-> a]] is an assertion [P'] that is just like [P] except that, wherever [P] looks up the variable [X] in the current state, [P'] instead uses the value of the expression [a]. To see how this works, let's calculate what happens with a couple of examples. First, suppose [P'] is [(X <= 5) [X |-> 3]] -- that is, more formally, [P'] is the Coq expression fun st => (fun st' => st' X <= 5) (update st X (aeval st (ANum 3))), which simplifies to fun st => (fun st' => st' X <= 5) (update st X 3) and further simplifies to fun st => ((update st X 3) X) <= 5) and by further simplification to fun st => (3 <= 5). That is, [P'] is the assertion that [3] is less than or equal to [5] (as expected). For a more interesting example, suppose [P'] is [(X <= 5) [X |-> X+1]]. Formally, [P'] is the Coq expression fun st => (fun st' => st' X <= 5) (update st X (aeval st (APlus (AId X) (ANum 1)))), which simplifies to fun st => (((update st X (aeval st (APlus (AId X) (ANum 1))))) X) <= 5 and further simplifies to fun st => (aeval st (APlus (AId X) (ANum 1))) <= 5. That is, [P'] is the assertion that [X+1] is at most [5]. *) (** Now we can give the precise proof rule for assignment: ------------------------------ (hoare_asgn) {{Q [X |-> a]}} X ::= a {{Q}} *) (** We can prove formally that this rule is indeed valid. *) Theorem hoare_asgn : forall Q X a, {{Q [X |-> a]}} (X ::= a) {{Q}}. Proof. unfold hoare_triple. intros Q X a st st' HE HQ. inversion HE. subst. unfold assn_sub in HQ. assumption. Qed. (** Here's a first formal proof using this rule. *) Example assn_sub_example : {{(fun st => st X = 3) [X |-> ANum 3]}} (X ::= (ANum 3)) {{fun st => st X = 3}}. Proof. apply hoare_asgn. Qed. (** **** Exercise: 2 stars (hoare_asgn_examples) *) (** Translate these informal Hoare triples... 1) {{ (X <= 5) [X |-> X + 1] }} X ::= X + 1 {{ X <= 5 }} 2) {{ (0 <= X /\ X <= 5) [X |-> 3] }} X ::= 3 {{ 0 <= X /\ X <= 5 }} ...into formal statements [assn_sub_ex1, assn_sub_ex2] and use [hoare_asgn] to prove them. *) (* FILL IN HERE *) (** [] *) (** **** Exercise: 2 stars (hoare_asgn_wrong) *) (** The assignment rule looks backward to almost everyone the first time they see it. If it still seems backward to you, it may help to think a little about alternative "forward" rules. Here is a seemingly natural one: ------------------------------ (hoare_asgn_wrong) {{ True }} X ::= a {{ X = a }} Give a counterexample showing that this rule is incorrect (informally). Hint: The rule universally quantifies over the arithmetic expression [a], and your counterexample needs to exhibit an [a] for which the rule doesn't work. *) (* FILL IN HERE *) (** [] *) (** **** Exercise: 3 stars, advanced (hoare_asgn_fwd) *) (** However, using an auxiliary variable [m] to remember the original value of [X] we can define a Hoare rule for assignment that does, intuitively, "work forwards" rather than backwards. ------------------------------------------ (hoare_asgn_fwd) {{fun st => P st /\ st X = m}} X ::= a {{fun st => P st' /\ st X = aeval st' a }} (where st' = update st X m) Note that we use the original value of [X] to reconstruct the state [st'] before the assignment took place. Prove that this rule is correct (the first hypothesis is the functional extensionality axiom, which you will need at some point). Also note that this rule is more complicated than [hoare_asgn]. *) Theorem hoare_asgn_fwd : (forall {X Y: Type} {f g : X -> Y}, (forall (x: X), f x = g x) -> f = g) -> forall m a P, {{fun st => P st /\ st X = m}} X ::= a {{fun st => P (update st X m) /\ st X = aeval (update st X m) a }}. Proof. intros functional_extensionality m a P. (* FILL IN HERE *) Admitted. (** [] *) (** **** Exercise: 2 stars, advanced (hoare_asgn_fwd_exists) *) (** Another way to define a forward rule for assignment is to existentially quantify over the previous value of the assigned variable. ------------------------------------------ (hoare_asgn_fwd_exists) {{fun st => P st}} X ::= a {{fun st => exists m, P (update st X m) /\ st X = aeval (update st X m) a }} *) (* This rule was proposed by Nick Giannarakis and Zoe Paraskevopoulou. *) Theorem hoare_asgn_fwd_exists : (forall {X Y: Type} {f g : X -> Y}, (forall (x: X), f x = g x) -> f = g) -> forall a P, {{fun st => P st}} X ::= a {{fun st => exists m, P (update st X m) /\ st X = aeval (update st X m) a }}. Proof. intros functional_extensionality a P. (* FILL IN HERE *) Admitted. (** [] *) (* ####################################################### *) (** *** Consequence *) (** Sometimes the preconditions and postconditions we get from the Hoare rules won't quite be the ones we want in the particular situation at hand -- they may be logically equivalent but have a different syntactic form that fails to unify with the goal we are trying to prove, or they actually may be logically weaker (for preconditions) or stronger (for postconditions) than what we need. For instance, while {{(X = 3) [X |-> 3]}} X ::= 3 {{X = 3}}, follows directly from the assignment rule, {{True}} X ::= 3 {{X = 3}}. does not. This triple is valid, but it is not an instance of [hoare_asgn] because [True] and [(X = 3) [X |-> 3]] are not syntactically equal assertions. However, they are logically equivalent, so if one triple is valid, then the other must certainly be as well. We might capture this observation with the following rule: {{P'}} c {{Q}} P <<->> P' ----------------------------- (hoare_consequence_pre_equiv) {{P}} c {{Q}} Taking this line of thought a bit further, we can see that strengthening the precondition or weakening the postcondition of a valid triple always produces another valid triple. This observation is captured by two _Rules of Consequence_. {{P'}} c {{Q}} P ->> P' ----------------------------- (hoare_consequence_pre) {{P}} c {{Q}} {{P}} c {{Q'}} Q' ->> Q ----------------------------- (hoare_consequence_post) {{P}} c {{Q}} *) (** Here are the formal versions: *) Theorem hoare_consequence_pre : forall (P P' Q : Assertion) c, {{P'}} c {{Q}} -> P ->> P' -> {{P}} c {{Q}}. Proof. intros P P' Q c Hhoare Himp. intros st st' Hc HP. apply (Hhoare st st'). assumption. apply Himp. assumption. Qed. Theorem hoare_consequence_post : forall (P Q Q' : Assertion) c, {{P}} c {{Q'}} -> Q' ->> Q -> {{P}} c {{Q}}. Proof. intros P Q Q' c Hhoare Himp. intros st st' Hc HP. apply Himp. apply (Hhoare st st'). assumption. assumption. Qed. (** For example, we might use the first consequence rule like this: {{ True }} ->> {{ 1 = 1 }} X ::= 1 {{ X = 1 }} Or, formally... *) Example hoare_asgn_example1 : {{fun st => True}} (X ::= (ANum 1)) {{fun st => st X = 1}}. Proof. apply hoare_consequence_pre with (P' := (fun st => st X = 1) [X |-> ANum 1]). apply hoare_asgn. intros st H. unfold assn_sub, update. simpl. reflexivity. Qed. (** Finally, for convenience in some proofs, we can state a "combined" rule of consequence that allows us to vary both the precondition and the postcondition. {{P'}} c {{Q'}} P ->> P' Q' ->> Q ----------------------------- (hoare_consequence) {{P}} c {{Q}} *) Theorem hoare_consequence : forall (P P' Q Q' : Assertion) c, {{P'}} c {{Q'}} -> P ->> P' -> Q' ->> Q -> {{P}} c {{Q}}. Proof. intros P P' Q Q' c Hht HPP' HQ'Q. apply hoare_consequence_pre with (P' := P'). apply hoare_consequence_post with (Q' := Q'). assumption. assumption. assumption. Qed. (* ####################################################### *) (** *** Digression: The [eapply] Tactic *) (** This is a good moment to introduce another convenient feature of Coq. We had to write "[with (P' := ...)]" explicitly in the proof of [hoare_asgn_example1] and [hoare_consequence] above, to make sure that all of the metavariables in the premises to the [hoare_consequence_pre] rule would be set to specific values. (Since [P'] doesn't appear in the conclusion of [hoare_consequence_pre], the process of unifying the conclusion with the current goal doesn't constrain [P'] to a specific assertion.) This is a little annoying, both because the assertion is a bit long and also because for [hoare_asgn_example1] the very next thing we are going to do -- applying the [hoare_asgn] rule -- will tell us exactly what it should be! We can use [eapply] instead of [apply] to tell Coq, essentially, "Be patient: The missing part is going to be filled in soon." *) Example hoare_asgn_example1' : {{fun st => True}} (X ::= (ANum 1)) {{fun st => st X = 1}}. Proof. eapply hoare_consequence_pre. apply hoare_asgn. intros st H. reflexivity. Qed. (** In general, [eapply H] tactic works just like [apply H] except that, instead of failing if unifying the goal with the conclusion of [H] does not determine how to instantiate all of the variables appearing in the premises of [H], [eapply H] will replace these variables with so-called _existential variables_ (written [?nnn]) as placeholders for expressions that will be determined (by further unification) later in the proof. *) (** In order for [Qed] to succeed, all existential variables need to be determined by the end of the proof. Otherwise Coq will (rightly) refuse to accept the proof. Remember that the Coq tactics build proof objects, and proof objects containing existential variables are not complete. *) Lemma silly1 : forall (P : nat -> nat -> Prop) (Q : nat -> Prop), (forall x y : nat, P x y) -> (forall x y : nat, P x y -> Q x) -> Q 42. Proof. intros P Q HP HQ. eapply HQ. apply HP. (** Coq gives a warning after [apply HP]: No more subgoals but non-instantiated existential variables: Existential 1 = ?171 : [P : nat -> nat -> Prop Q : nat -> Prop HP : forall x y : nat, P x y HQ : forall x y : nat, P x y -> Q x |- nat] (dependent evars: ?171 open,) You can use Grab Existential Variables. Trying to finish the proof with [Qed] gives an error: << Error: Attempt to save a proof with existential variables still non-instantiated >> *) Abort. (** An additional constraint is that existential variables cannot be instantiated with terms containing (ordinary) variables that did not exist at the time the existential variable was created. *) Lemma silly2 : forall (P : nat -> nat -> Prop) (Q : nat -> Prop), (exists y, P 42 y) -> (forall x y : nat, P x y -> Q x) -> Q 42. Proof. intros P Q HP HQ. eapply HQ. destruct HP as [y HP']. (** Doing [apply HP'] above fails with the following error: Error: Impossible to unify "?175" with "y". In this case there is an easy fix: doing [destruct HP] _before_ doing [eapply HQ]. *) Abort. Lemma silly2_fixed : forall (P : nat -> nat -> Prop) (Q : nat -> Prop), (exists y, P 42 y) -> (forall x y : nat, P x y -> Q x) -> Q 42. Proof. intros P Q HP HQ. destruct HP as [y HP']. eapply HQ. apply HP'. Qed. (** In the last step we did [apply HP'] which unifies the existential variable in the goal with the variable [y]. The [assumption] tactic doesn't work in this case, since it cannot handle existential variables. However, Coq also provides an [eassumption] tactic that solves the goal if one of the premises matches the goal up to instantiations of existential variables. We can use it instead of [apply HP']. *) Lemma silly2_eassumption : forall (P : nat -> nat -> Prop) (Q : nat -> Prop), (exists y, P 42 y) -> (forall x y : nat, P x y -> Q x) -> Q 42. Proof. intros P Q HP HQ. destruct HP as [y HP']. eapply HQ. eassumption. Qed. (** **** Exercise: 2 stars (hoare_asgn_examples_2) *) (** Translate these informal Hoare triples... {{ X + 1 <= 5 }} X ::= X + 1 {{ X <= 5 }} {{ 0 <= 3 /\ 3 <= 5 }} X ::= 3 {{ 0 <= X /\ X <= 5 }} ...into formal statements [assn_sub_ex1', assn_sub_ex2'] and use [hoare_asgn] and [hoare_consequence_pre] to prove them. *) (* FILL IN HERE *) (** [] *) (* ####################################################### *) (** *** Skip *) (** Since [SKIP] doesn't change the state, it preserves any property P: -------------------- (hoare_skip) {{ P }} SKIP {{ P }} *) Theorem hoare_skip : forall P, {{P}} SKIP {{P}}. Proof. intros P st st' H HP. inversion H. subst. assumption. Qed. (* ####################################################### *) (** *** Sequencing *) (** More interestingly, if the command [c1] takes any state where [P] holds to a state where [Q] holds, and if [c2] takes any state where [Q] holds to one where [R] holds, then doing [c1] followed by [c2] will take any state where [P] holds to one where [R] holds: {{ P }} c1 {{ Q }} {{ Q }} c2 {{ R }} --------------------- (hoare_seq) {{ P }} c1;;c2 {{ R }} *) Theorem hoare_seq : forall P Q R c1 c2, {{Q}} c2 {{R}} -> {{P}} c1 {{Q}} -> {{P}} c1;;c2 {{R}}. Proof. intros P Q R c1 c2 H1 H2 st st' H12 Pre. inversion H12; subst. apply (H1 st'0 st'); try assumption. apply (H2 st st'0); assumption. Qed. (** Note that, in the formal rule [hoare_seq], the premises are given in "backwards" order ([c2] before [c1]). This matches the natural flow of information in many of the situations where we'll use the rule: the natural way to construct a Hoare-logic proof is to begin at the end of the program (with the final postcondition) and push postconditions backwards through commands until we reach the beginning. *) (** Informally, a nice way of recording a proof using the sequencing rule is as a "decorated program" where the intermediate assertion [Q] is written between [c1] and [c2]: {{ a = n }} X ::= a;; {{ X = n }} <---- decoration for Q SKIP {{ X = n }} *) Example hoare_asgn_example3 : forall a n, {{fun st => aeval st a = n}} (X ::= a;; SKIP) {{fun st => st X = n}}. Proof. intros a n. eapply hoare_seq. Case "right part of seq". apply hoare_skip. Case "left part of seq". eapply hoare_consequence_pre. apply hoare_asgn. intros st H. subst. reflexivity. Qed. (** You will most often use [hoare_seq] and [hoare_consequence_pre] in conjunction with the [eapply] tactic, as done above. *) (** **** Exercise: 2 stars (hoare_asgn_example4) *) (** Translate this "decorated program" into a formal proof: {{ True }} ->> {{ 1 = 1 }} X ::= 1;; {{ X = 1 }} ->> {{ X = 1 /\ 2 = 2 }} Y ::= 2 {{ X = 1 /\ Y = 2 }} *) Example hoare_asgn_example4 : {{fun st => True}} (X ::= (ANum 1);; Y ::= (ANum 2)) {{fun st => st X = 1 /\ st Y = 2}}. Proof. (* FILL IN HERE *) Admitted. (** [] *) (** **** Exercise: 3 stars (swap_exercise) *) (** Write an Imp program [c] that swaps the values of [X] and [Y] and show (in Coq) that it satisfies the following specification: {{X <= Y}} c {{Y <= X}} *) Definition swap_program : com := (* FILL IN HERE *) admit. Theorem swap_exercise : {{fun st => st X <= st Y}} swap_program {{fun st => st Y <= st X}}. Proof. (* FILL IN HERE *) Admitted. (** [] *) (** **** Exercise: 3 stars (hoarestate1) *) (** Explain why the following proposition can't be proven: forall (a : aexp) (n : nat), {{fun st => aeval st a = n}} (X ::= (ANum 3);; Y ::= a) {{fun st => st Y = n}}. *) (* FILL IN HERE *) (** [] *) (* ####################################################### *) (** *** Conditionals *) (** What sort of rule do we want for reasoning about conditional commands? Certainly, if the same assertion [Q] holds after executing either branch, then it holds after the whole conditional. So we might be tempted to write: {{P}} c1 {{Q}} {{P}} c2 {{Q}} -------------------------------- {{P}} IFB b THEN c1 ELSE c2 {{Q}} However, this is rather weak. For example, using this rule, we cannot show that: {{ True }} IFB X == 0 THEN Y ::= 2 ELSE Y ::= X + 1 FI {{ X <= Y }} since the rule tells us nothing about the state in which the assignments take place in the "then" and "else" branches. *) (** But we can actually say something more precise. In the "then" branch, we know that the boolean expression [b] evaluates to [true], and in the "else" branch, we know it evaluates to [false]. Making this information available in the premises of the rule gives us more information to work with when reasoning about the behavior of [c1] and [c2] (i.e., the reasons why they establish the postcondition [Q]). *) (** {{P /\ b}} c1 {{Q}} {{P /\ ~b}} c2 {{Q}} ------------------------------------ (hoare_if) {{P}} IFB b THEN c1 ELSE c2 FI {{Q}} *) (** To interpret this rule formally, we need to do a little work. Strictly speaking, the assertion we've written, [P /\ b], is the conjunction of an assertion and a boolean expression -- i.e., it doesn't typecheck. To fix this, we need a way of formally "lifting" any bexp [b] to an assertion. We'll write [bassn b] for the assertion "the boolean expression [b] evaluates to [true] (in the given state)." *) Definition bassn b : Assertion := fun st => (beval st b = true). (** A couple of useful facts about [bassn]: *) Lemma bexp_eval_true : forall b st, beval st b = true -> (bassn b) st. Proof. intros b st Hbe. unfold bassn. assumption. Qed. Lemma bexp_eval_false : forall b st, beval st b = false -> ~ ((bassn b) st). Proof. intros b st Hbe contra. unfold bassn in contra. rewrite -> contra in Hbe. inversion Hbe. Qed. (** Now we can formalize the Hoare proof rule for conditionals and prove it correct. *) Theorem hoare_if : forall P Q b c1 c2, {{fun st => P st /\ bassn b st}} c1 {{Q}} -> {{fun st => P st /\ ~(bassn b st)}} c2 {{Q}} -> {{P}} (IFB b THEN c1 ELSE c2 FI) {{Q}}. Proof. intros P Q b c1 c2 HTrue HFalse st st' HE HP. inversion HE; subst. Case "b is true". apply (HTrue st st'). assumption. split. assumption. apply bexp_eval_true. assumption. Case "b is false". apply (HFalse st st'). assumption. split. assumption. apply bexp_eval_false. assumption. Qed. (* ####################################################### *) (** * Hoare Logic: So Far *) (** Idea: create a _domain specific logic_ for reasoning about properties of Imp programs. - This hides the low-level details of the semantics of the program - Leads to a compositional reasoning process The basic structure is given by _Hoare triples_ of the form: {{P}} c {{Q}} ]] - [P] and [Q] are predicates about the state of the Imp program - "If command [c] is started in a state satisfying assertion [P], and if [c] eventually terminates in some final state, then this final state will satisfy the assertion [Q]." *) (** ** Hoare Logic Rules (so far) *) (** ------------------------------ (hoare_asgn) {{Q [X |-> a]}} X::=a {{Q}} -------------------- (hoare_skip) {{ P }} SKIP {{ P }} {{ P }} c1 {{ Q }} {{ Q }} c2 {{ R }} --------------------- (hoare_seq) {{ P }} c1;;c2 {{ R }} {{P /\ b}} c1 {{Q}} {{P /\ ~b}} c2 {{Q}} ------------------------------------ (hoare_if) {{P}} IFB b THEN c1 ELSE c2 FI {{Q}} {{P'}} c {{Q'}} P ->> P' Q' ->> Q ----------------------------- (hoare_consequence) {{P}} c {{Q}} *) (** *** Example *) (** Here is a formal proof that the program we used to motivate the rule satisfies the specification we gave. *) Example if_example : {{fun st => True}} IFB (BEq (AId X) (ANum 0)) THEN (Y ::= (ANum 2)) ELSE (Y ::= APlus (AId X) (ANum 1)) FI {{fun st => st X <= st Y}}. Proof. (* WORKED IN CLASS *) apply hoare_if. Case "Then". eapply hoare_consequence_pre. apply hoare_asgn. unfold bassn, assn_sub, update, assert_implies. simpl. intros st [_ H]. apply beq_nat_true in H. rewrite H. omega. Case "Else". eapply hoare_consequence_pre. apply hoare_asgn. unfold assn_sub, update, assert_implies. simpl; intros st _. omega. Qed. (** **** Exercise: 2 stars (if_minus_plus) *) (** Prove the following hoare triple using [hoare_if]: *) Theorem if_minus_plus : {{fun st => True}} IFB (BLe (AId X) (AId Y)) THEN (Z ::= AMinus (AId Y) (AId X)) ELSE (Y ::= APlus (AId X) (AId Z)) FI {{fun st => st Y = st X + st Z}}. Proof. (* FILL IN HERE *) Admitted. (* ####################################################### *) (** *** Exercise: One-sided conditionals *) (** **** Exercise: 4 stars (if1_hoare) *) (** In this exercise we consider extending Imp with "one-sided conditionals" of the form [IF1 b THEN c FI]. Here [b] is a boolean expression, and [c] is a command. If [b] evaluates to [true], then command [c] is evaluated. If [b] evaluates to [false], then [IF1 b THEN c FI] does nothing. We recommend that you do this exercise before the ones that follow, as it should help solidify your understanding of the material. *) (** The first step is to extend the syntax of commands and introduce the usual notations. (We've done this for you. We use a separate module to prevent polluting the global name space.) *) Module If1. Inductive com : Type := | CSkip : com | CAss : id -> aexp -> com | CSeq : com -> com -> com | CIf : bexp -> com -> com -> com | CWhile : bexp -> com -> com | CIf1 : bexp -> com -> com. Tactic Notation "com_cases" tactic(first) ident(c) := first; [ Case_aux c "SKIP" | Case_aux c "::=" | Case_aux c ";" | Case_aux c "IFB" | Case_aux c "WHILE" | Case_aux c "CIF1" ]. Notation "'SKIP'" := CSkip. Notation "c1 ;; c2" := (CSeq c1 c2) (at level 80, right associativity). Notation "X '::=' a" := (CAss X a) (at level 60). Notation "'WHILE' b 'DO' c 'END'" := (CWhile b c) (at level 80, right associativity). Notation "'IFB' e1 'THEN' e2 'ELSE' e3 'FI'" := (CIf e1 e2 e3) (at level 80, right associativity). Notation "'IF1' b 'THEN' c 'FI'" := (CIf1 b c) (at level 80, right associativity). (** Next we need to extend the evaluation relation to accommodate [IF1] branches. This is for you to do... What rule(s) need to be added to [ceval] to evaluate one-sided conditionals? *) Reserved Notation "c1 '/' st '||' st'" (at level 40, st at level 39). Inductive ceval : com -> state -> state -> Prop := | E_Skip : forall st : state, SKIP / st || st | E_Ass : forall (st : state) (a1 : aexp) (n : nat) (X : id), aeval st a1 = n -> (X ::= a1) / st || update st X n | E_Seq : forall (c1 c2 : com) (st st' st'' : state), c1 / st || st' -> c2 / st' || st'' -> (c1 ;; c2) / st || st'' | E_IfTrue : forall (st st' : state) (b1 : bexp) (c1 c2 : com), beval st b1 = true -> c1 / st || st' -> (IFB b1 THEN c1 ELSE c2 FI) / st || st' | E_IfFalse : forall (st st' : state) (b1 : bexp) (c1 c2 : com), beval st b1 = false -> c2 / st || st' -> (IFB b1 THEN c1 ELSE c2 FI) / st || st' | E_WhileEnd : forall (b1 : bexp) (st : state) (c1 : com), beval st b1 = false -> (WHILE b1 DO c1 END) / st || st | E_WhileLoop : forall (st st' st'' : state) (b1 : bexp) (c1 : com), beval st b1 = true -> c1 / st || st' -> (WHILE b1 DO c1 END) / st' || st'' -> (WHILE b1 DO c1 END) / st || st'' (* FILL IN HERE *) where "c1 '/' st '||' st'" := (ceval c1 st st'). Tactic Notation "ceval_cases" tactic(first) ident(c) := first; [ Case_aux c "E_Skip" | Case_aux c "E_Ass" | Case_aux c "E_Seq" | Case_aux c "E_IfTrue" | Case_aux c "E_IfFalse" | Case_aux c "E_WhileEnd" | Case_aux c "E_WhileLoop" (* FILL IN HERE *) ]. (** Now we repeat (verbatim) the definition and notation of Hoare triples. *) Definition hoare_triple (P:Assertion) (c:com) (Q:Assertion) : Prop := forall st st', c / st || st' -> P st -> Q st'. Notation "{{ P }} c {{ Q }}" := (hoare_triple P c Q) (at level 90, c at next level) : hoare_spec_scope. (** Finally, we (i.e., you) need to state and prove a theorem, [hoare_if1], that expresses an appropriate Hoare logic proof rule for one-sided conditionals. Try to come up with a rule that is both sound and as precise as possible. *) (* FILL IN HERE *) (** For full credit, prove formally [hoare_if1_good] that your rule is precise enough to show the following valid Hoare triple: {{ X + Y = Z }} IF1 Y <> 0 THEN X ::= X + Y FI {{ X = Z }} *) (** Hint: Your proof of this triple may need to use the other proof rules also. Because we're working in a separate module, you'll need to copy here the rules you find necessary. *) Lemma hoare_if1_good : {{ fun st => st X + st Y = st Z }} IF1 BNot (BEq (AId Y) (ANum 0)) THEN X ::= APlus (AId X) (AId Y) FI {{ fun st => st X = st Z }}. Proof. (* FILL IN HERE *) Admitted. End If1. (** [] *) (* ####################################################### *) (** *** Loops *) (** Finally, we need a rule for reasoning about while loops. *) (** Suppose we have a loop WHILE b DO c END and we want to find a pre-condition [P] and a post-condition [Q] such that {{P}} WHILE b DO c END {{Q}} is a valid triple. *) (** *** *) (** First of all, let's think about the case where [b] is false at the beginning -- i.e., let's assume that the loop body never executes at all. In this case, the loop behaves like [SKIP], so we might be tempted to write: *) (** {{P}} WHILE b DO c END {{P}}. *) (** But, as we remarked above for the conditional, we know a little more at the end -- not just [P], but also the fact that [b] is false in the current state. So we can enrich the postcondition a little: *) (** {{P}} WHILE b DO c END {{P /\ ~b}} *) (** What about the case where the loop body _does_ get executed? In order to ensure that [P] holds when the loop finally exits, we certainly need to make sure that the command [c] guarantees that [P] holds whenever [c] is finished. Moreover, since [P] holds at the beginning of the first execution of [c], and since each execution of [c] re-establishes [P] when it finishes, we can always assume that [P] holds at the beginning of [c]. This leads us to the following rule: *) (** {{P}} c {{P}} ----------------------------------- {{P}} WHILE b DO c END {{P /\ ~b}} *) (** This is almost the rule we want, but again it can be improved a little: at the beginning of the loop body, we know not only that [P] holds, but also that the guard [b] is true in the current state. This gives us a little more information to use in reasoning about [c] (showing that it establishes the invariant by the time it finishes). This gives us the final version of the rule: *) (** {{P /\ b}} c {{P}} ----------------------------------- (hoare_while) {{P}} WHILE b DO c END {{P /\ ~b}} The proposition [P] is called an _invariant_ of the loop. *) Lemma hoare_while : forall P b c, {{fun st => P st /\ bassn b st}} c {{P}} -> {{P}} WHILE b DO c END {{fun st => P st /\ ~ (bassn b st)}}. Proof. intros P b c Hhoare st st' He HP. (* Like we've seen before, we need to reason by induction on [He], because, in the "keep looping" case, its hypotheses talk about the whole loop instead of just [c]. *) remember (WHILE b DO c END) as wcom eqn:Heqwcom. ceval_cases (induction He) Case; try (inversion Heqwcom); subst; clear Heqwcom. Case "E_WhileEnd". split. assumption. apply bexp_eval_false. assumption. Case "E_WhileLoop". apply IHHe2. reflexivity. apply (Hhoare st st'). assumption. split. assumption. apply bexp_eval_true. assumption. Qed. (** One subtlety in the terminology is that calling some assertion [P] a "loop invariant" doesn't just mean that it is preserved by the body of the loop in question (i.e., [{{P}} c {{P}}], where [c] is the loop body), but rather that [P] _together with the fact that the loop's guard is true_ is a sufficient precondition for [c] to ensure [P] as a postcondition. This is a slightly (but significantly) weaker requirement. For example, if [P] is the assertion [X = 0], then [P] _is_ an invariant of the loop WHILE X = 2 DO X := 1 END although it is clearly _not_ preserved by the body of the loop. *) Example while_example : {{fun st => st X <= 3}} WHILE (BLe (AId X) (ANum 2)) DO X ::= APlus (AId X) (ANum 1) END {{fun st => st X = 3}}. Proof. eapply hoare_consequence_post. apply hoare_while. eapply hoare_consequence_pre. apply hoare_asgn. unfold bassn, assn_sub, assert_implies, update. simpl. intros st [H1 H2]. apply ble_nat_true in H2. omega. unfold bassn, assert_implies. intros st [Hle Hb]. simpl in Hb. destruct (ble_nat (st X) 2) eqn : Heqle. apply ex_falso_quodlibet. apply Hb; reflexivity. apply ble_nat_false in Heqle. omega. Qed. (** *** *) (** We can use the while rule to prove the following Hoare triple, which may seem surprising at first... *) Theorem always_loop_hoare : forall P Q, {{P}} WHILE BTrue DO SKIP END {{Q}}. Proof. (* WORKED IN CLASS *) intros P Q. apply hoare_consequence_pre with (P' := fun st : state => True). eapply hoare_consequence_post. apply hoare_while. Case "Loop body preserves invariant". apply hoare_post_true. intros st. apply I. Case "Loop invariant and negated guard imply postcondition". simpl. intros st [Hinv Hguard]. apply ex_falso_quodlibet. apply Hguard. reflexivity. Case "Precondition implies invariant". intros st H. constructor. Qed. (** Of course, this result is not surprising if we remember that the definition of [hoare_triple] asserts that the postcondition must hold _only_ when the command terminates. If the command doesn't terminate, we can prove anything we like about the post-condition. *) (** Hoare rules that only talk about terminating commands are often said to describe a logic of "partial" correctness. It is also possible to give Hoare rules for "total" correctness, which build in the fact that the commands terminate. However, in this course we will only talk about partial correctness. *) (* ####################################################### *) (** *** Exercise: [REPEAT] *) Module RepeatExercise. (** **** Exercise: 4 stars, advanced (hoare_repeat) *) (** In this exercise, we'll add a new command to our language of commands: [REPEAT] c [UNTIL] a [END]. You will write the evaluation rule for [repeat] and add a new Hoare rule to the language for programs involving it. *) Inductive com : Type := | CSkip : com | CAsgn : id -> aexp -> com | CSeq : com -> com -> com | CIf : bexp -> com -> com -> com | CWhile : bexp -> com -> com | CRepeat : com -> bexp -> com. (** [REPEAT] behaves like [WHILE], except that the loop guard is checked _after_ each execution of the body, with the loop repeating as long as the guard stays _false_. Because of this, the body will always execute at least once. *) Tactic Notation "com_cases" tactic(first) ident(c) := first; [ Case_aux c "SKIP" | Case_aux c "::=" | Case_aux c ";" | Case_aux c "IFB" | Case_aux c "WHILE" | Case_aux c "CRepeat" ]. Notation "'SKIP'" := CSkip. Notation "c1 ;; c2" := (CSeq c1 c2) (at level 80, right associativity). Notation "X '::=' a" := (CAsgn X a) (at level 60). Notation "'WHILE' b 'DO' c 'END'" := (CWhile b c) (at level 80, right associativity). Notation "'IFB' e1 'THEN' e2 'ELSE' e3 'FI'" := (CIf e1 e2 e3) (at level 80, right associativity). Notation "'REPEAT' e1 'UNTIL' b2 'END'" := (CRepeat e1 b2) (at level 80, right associativity). (** Add new rules for [REPEAT] to [ceval] below. You can use the rules for [WHILE] as a guide, but remember that the body of a [REPEAT] should always execute at least once, and that the loop ends when the guard becomes true. Then update the [ceval_cases] tactic to handle these added cases. *) Inductive ceval : state -> com -> state -> Prop := | E_Skip : forall st, ceval st SKIP st | E_Ass : forall st a1 n X, aeval st a1 = n -> ceval st (X ::= a1) (update st X n) | E_Seq : forall c1 c2 st st' st'', ceval st c1 st' -> ceval st' c2 st'' -> ceval st (c1 ;; c2) st'' | E_IfTrue : forall st st' b1 c1 c2, beval st b1 = true -> ceval st c1 st' -> ceval st (IFB b1 THEN c1 ELSE c2 FI) st' | E_IfFalse : forall st st' b1 c1 c2, beval st b1 = false -> ceval st c2 st' -> ceval st (IFB b1 THEN c1 ELSE c2 FI) st' | E_WhileEnd : forall b1 st c1, beval st b1 = false -> ceval st (WHILE b1 DO c1 END) st | E_WhileLoop : forall st st' st'' b1 c1, beval st b1 = true -> ceval st c1 st' -> ceval st' (WHILE b1 DO c1 END) st'' -> ceval st (WHILE b1 DO c1 END) st'' (* FILL IN HERE *) . Tactic Notation "ceval_cases" tactic(first) ident(c) := first; [ Case_aux c "E_Skip" | Case_aux c "E_Ass" | Case_aux c "E_Seq" | Case_aux c "E_IfTrue" | Case_aux c "E_IfFalse" | Case_aux c "E_WhileEnd" | Case_aux c "E_WhileLoop" (* FILL IN HERE *) ]. (** A couple of definitions from above, copied here so they use the new [ceval]. *) Notation "c1 '/' st '||' st'" := (ceval st c1 st') (at level 40, st at level 39). Definition hoare_triple (P:Assertion) (c:com) (Q:Assertion) : Prop := forall st st', (c / st || st') -> P st -> Q st'. Notation "{{ P }} c {{ Q }}" := (hoare_triple P c Q) (at level 90, c at next level). (** To make sure you've got the evaluation rules for [REPEAT] right, prove that [ex1_repeat evaluates correctly. *) Definition ex1_repeat := REPEAT X ::= ANum 1;; Y ::= APlus (AId Y) (ANum 1) UNTIL (BEq (AId X) (ANum 1)) END. Theorem ex1_repeat_works : ex1_repeat / empty_state || update (update empty_state X 1) Y 1. Proof. (* FILL IN HERE *) Admitted. (** Now state and prove a theorem, [hoare_repeat], that expresses an appropriate proof rule for [repeat] commands. Use [hoare_while] as a model, and try to make your rule as precise as possible. *) (* FILL IN HERE *) (** For full credit, make sure (informally) that your rule can be used to prove the following valid Hoare triple: {{ X > 0 }} REPEAT Y ::= X;; X ::= X - 1 UNTIL X = 0 END {{ X = 0 /\ Y > 0 }} *) End RepeatExercise. (** [] *) (* ####################################################### *) (** ** Exercise: [HAVOC] *) (** **** Exercise: 3 stars (himp_hoare) *) (** In this exercise, we will derive proof rules for the [HAVOC] command which we studied in the last chapter. First, we enclose this work in a separate module, and recall the syntax and big-step semantics of Himp commands. *) Module Himp. Inductive com : Type := | CSkip : com | CAsgn : id -> aexp -> com | CSeq : com -> com -> com | CIf : bexp -> com -> com -> com | CWhile : bexp -> com -> com | CHavoc : id -> com. Tactic Notation "com_cases" tactic(first) ident(c) := first; [ Case_aux c "SKIP" | Case_aux c "::=" | Case_aux c ";" | Case_aux c "IFB" | Case_aux c "WHILE" | Case_aux c "HAVOC" ]. Notation "'SKIP'" := CSkip. Notation "X '::=' a" := (CAsgn X a) (at level 60). Notation "c1 ;; c2" := (CSeq c1 c2) (at level 80, right associativity). Notation "'WHILE' b 'DO' c 'END'" := (CWhile b c) (at level 80, right associativity). Notation "'IFB' e1 'THEN' e2 'ELSE' e3 'FI'" := (CIf e1 e2 e3) (at level 80, right associativity). Notation "'HAVOC' X" := (CHavoc X) (at level 60). Reserved Notation "c1 '/' st '||' st'" (at level 40, st at level 39). Inductive ceval : com -> state -> state -> Prop := | E_Skip : forall st : state, SKIP / st || st | E_Ass : forall (st : state) (a1 : aexp) (n : nat) (X : id), aeval st a1 = n -> (X ::= a1) / st || update st X n | E_Seq : forall (c1 c2 : com) (st st' st'' : state), c1 / st || st' -> c2 / st' || st'' -> (c1 ;; c2) / st || st'' | E_IfTrue : forall (st st' : state) (b1 : bexp) (c1 c2 : com), beval st b1 = true -> c1 / st || st' -> (IFB b1 THEN c1 ELSE c2 FI) / st || st' | E_IfFalse : forall (st st' : state) (b1 : bexp) (c1 c2 : com), beval st b1 = false -> c2 / st || st' -> (IFB b1 THEN c1 ELSE c2 FI) / st || st' | E_WhileEnd : forall (b1 : bexp) (st : state) (c1 : com), beval st b1 = false -> (WHILE b1 DO c1 END) / st || st | E_WhileLoop : forall (st st' st'' : state) (b1 : bexp) (c1 : com), beval st b1 = true -> c1 / st || st' -> (WHILE b1 DO c1 END) / st' || st'' -> (WHILE b1 DO c1 END) / st || st'' | E_Havoc : forall (st : state) (X : id) (n : nat), (HAVOC X) / st || update st X n where "c1 '/' st '||' st'" := (ceval c1 st st'). Tactic Notation "ceval_cases" tactic(first) ident(c) := first; [ Case_aux c "E_Skip" | Case_aux c "E_Ass" | Case_aux c "E_Seq" | Case_aux c "E_IfTrue" | Case_aux c "E_IfFalse" | Case_aux c "E_WhileEnd" | Case_aux c "E_WhileLoop" | Case_aux c "E_Havoc" ]. (** The definition of Hoare triples is exactly as before. Unlike our notion of program equivalence, which had subtle consequences with occassionally nonterminating commands (exercise [havoc_diverge]), this definition is still fully satisfactory. Convince yourself of this before proceeding. *) Definition hoare_triple (P:Assertion) (c:com) (Q:Assertion) : Prop := forall st st', c / st || st' -> P st -> Q st'. Notation "{{ P }} c {{ Q }}" := (hoare_triple P c Q) (at level 90, c at next level) : hoare_spec_scope. (** Complete the Hoare rule for [HAVOC] commands below by defining [havoc_pre] and prove that the resulting rule is correct. *) Definition havoc_pre (X : id) (Q : Assertion) : Assertion := (* FILL IN HERE *) admit. Theorem hoare_havoc : forall (Q : Assertion) (X : id), {{ havoc_pre X Q }} HAVOC X {{ Q }}. Proof. (* FILL IN HERE *) Admitted. End Himp. (** [] *) (* ####################################################### *) (** ** Complete List of Hoare Logic Rules *) (** Above, we've introduced Hoare Logic as a tool to reasoning about Imp programs. In the reminder of this chapter we will explore a systematic way to use Hoare Logic to prove properties about programs. The rules of Hoare Logic are the following: *) (** ------------------------------ (hoare_asgn) {{Q [X |-> a]}} X::=a {{Q}} -------------------- (hoare_skip) {{ P }} SKIP {{ P }} {{ P }} c1 {{ Q }} {{ Q }} c2 {{ R }} --------------------- (hoare_seq) {{ P }} c1;;c2 {{ R }} {{P /\ b}} c1 {{Q}} {{P /\ ~b}} c2 {{Q}} ------------------------------------ (hoare_if) {{P}} IFB b THEN c1 ELSE c2 FI {{Q}} {{P /\ b}} c {{P}} ----------------------------------- (hoare_while) {{P}} WHILE b DO c END {{P /\ ~b}} {{P'}} c {{Q'}} P ->> P' Q' ->> Q ----------------------------- (hoare_consequence) {{P}} c {{Q}} In the next chapter, we'll see how these rules are used to prove that programs satisfy specifications of their behavior. *) (** $Date: 2014-12-31 11:17:56 -0500 (Wed, 31 Dec 2014) $ *)
(** * Hoare: Hoare Logic, Part I *) Require Export Imp. (** In the past couple of chapters, we've begun applying the mathematical tools developed in the first part of the course to studying the theory of a small programming language, Imp. - We defined a type of _abstract syntax trees_ for Imp, together with an _evaluation relation_ (a partial function on states) that specifies the _operational semantics_ of programs. The language we defined, though small, captures some of the key features of full-blown languages like C, C++, and Java, including the fundamental notion of mutable state and some common control structures. - We proved a number of _metatheoretic properties_ -- "meta" in the sense that they are properties of the language as a whole, rather than properties of particular programs in the language. These included: - determinism of evaluation - equivalence of some different ways of writing down the definitions (e.g. functional and relational definitions of arithmetic expression evaluation) - guaranteed termination of certain classes of programs - correctness (in the sense of preserving meaning) of a number of useful program transformations - behavioral equivalence of programs (in the [Equiv] chapter). If we stopped here, we would already have something useful: a set of tools for defining and discussing programming languages and language features that are mathematically precise, flexible, and easy to work with, applied to a set of key properties. All of these properties are things that language designers, compiler writers, and users might care about knowing. Indeed, many of them are so fundamental to our understanding of the programming languages we deal with that we might not consciously recognize them as "theorems." But properties that seem intuitively obvious can sometimes be quite subtle (in some cases, even subtly wrong!). We'll return to the theme of metatheoretic properties of whole languages later in the course when we discuss _types_ and _type soundness_. In this chapter, though, we'll turn to a different set of issues. Our goal is to see how to carry out some simple examples of _program verification_ -- i.e., using the precise definition of Imp to prove formally that particular programs satisfy particular specifications of their behavior. We'll develop a reasoning system called _Floyd-Hoare Logic_ -- often shortened to just _Hoare Logic_ -- in which each of the syntactic constructs of Imp is equipped with a single, generic "proof rule" that can be used to reason compositionally about the correctness of programs involving this construct. Hoare Logic originates in the 1960s, and it continues to be the subject of intensive research right up to the present day. It lies at the core of a multitude of tools that are being used in academia and industry to specify and verify real software systems. *) (* ####################################################### *) (** * Hoare Logic *) (** Hoare Logic combines two beautiful ideas: a natural way of writing down _specifications_ of programs, and a _compositional proof technique_ for proving that programs are correct with respect to such specifications -- where by "compositional" we mean that the structure of proofs directly mirrors the structure of the programs that they are about. *) (* ####################################################### *) (** ** Assertions *) (** To talk about specifications of programs, the first thing we need is a way of making _assertions_ about properties that hold at particular points during a program's execution -- i.e., claims about the current state of the memory when program execution reaches that point. Formally, an assertion is just a family of propositions indexed by a [state]. *) Definition Assertion := state -> Prop. (** **** Exercise: 1 star, optional (assertions) *) Module ExAssertions. (** Paraphrase the following assertions in English. *) Definition as1 : Assertion := fun st => st X = 3. Definition as2 : Assertion := fun st => st X <= st Y. Definition as3 : Assertion := fun st => st X = 3 \/ st X <= st Y. Definition as4 : Assertion := fun st => st Z * st Z <= st X /\ ~ (((S (st Z)) * (S (st Z))) <= st X). Definition as5 : Assertion := fun st => True. Definition as6 : Assertion := fun st => False. (* FILL IN HERE *) End ExAssertions. (** [] *) (* ####################################################### *) (** ** Notation for Assertions *) (** This way of writing assertions can be a little bit heavy, for two reasons: (1) every single assertion that we ever write is going to begin with [fun st => ]; and (2) this state [st] is the only one that we ever use to look up variables (we will never need to talk about two different memory states at the same time). For discussing examples informally, we'll adopt some simplifying conventions: we'll drop the initial [fun st =>], and we'll write just [X] to mean [st X]. Thus, instead of writing *) (** fun st => (st Z) * (st Z) <= m /\ ~ ((S (st Z)) * (S (st Z)) <= m) we'll write just Z * Z <= m /\ ~((S Z) * (S Z) <= m). *) (** Given two assertions [P] and [Q], we say that [P] _implies_ [Q], written [P ->> Q] (in ASCII, [P -][>][> Q]), if, whenever [P] holds in some state [st], [Q] also holds. *) Definition assert_implies (P Q : Assertion) : Prop := forall st, P st -> Q st. Notation "P ->> Q" := (assert_implies P Q) (at level 80) : hoare_spec_scope. Open Scope hoare_spec_scope. (** We'll also have occasion to use the "iff" variant of implication between assertions: *) Notation "P <<->> Q" := (P ->> Q /\ Q ->> P) (at level 80) : hoare_spec_scope. (* ####################################################### *) (** ** Hoare Triples *) (** Next, we need a way of making formal claims about the behavior of commands. *) (** Since the behavior of a command is to transform one state to another, it is natural to express claims about commands in terms of assertions that are true before and after the command executes: - "If command [c] is started in a state satisfying assertion [P], and if [c] eventually terminates in some final state, then this final state will satisfy the assertion [Q]." Such a claim is called a _Hoare Triple_. The property [P] is called the _precondition_ of [c], while [Q] is the _postcondition_. Formally: *) Definition hoare_triple (P:Assertion) (c:com) (Q:Assertion) : Prop := forall st st', c / st || st' -> P st -> Q st'. (** Since we'll be working a lot with Hoare triples, it's useful to have a compact notation: {{P}} c {{Q}}. *) (** (The traditional notation is [{P} c {Q}], but single braces are already used for other things in Coq.) *) Notation "{{ P }} c {{ Q }}" := (hoare_triple P c Q) (at level 90, c at next level) : hoare_spec_scope. (** (The [hoare_spec_scope] annotation here tells Coq that this notation is not global but is intended to be used in particular contexts. The [Open Scope] tells Coq that this file is one such context.) *) (** **** Exercise: 1 star, optional (triples) *) (** Paraphrase the following Hoare triples in English. 1) {{True}} c {{X = 5}} 2) {{X = m}} c {{X = m + 5)}} 3) {{X <= Y}} c {{Y <= X}} 4) {{True}} c {{False}} 5) {{X = m}} c {{Y = real_fact m}}. 6) {{True}} c {{(Z * Z) <= m /\ ~ (((S Z) * (S Z)) <= m)}} *) (** [] *) (** **** Exercise: 1 star, optional (valid_triples) *) (** Which of the following Hoare triples are _valid_ -- i.e., the claimed relation between [P], [c], and [Q] is true? 1) {{True}} X ::= 5 {{X = 5}} 2) {{X = 2}} X ::= X + 1 {{X = 3}} 3) {{True}} X ::= 5; Y ::= 0 {{X = 5}} 4) {{X = 2 /\ X = 3}} X ::= 5 {{X = 0}} 5) {{True}} SKIP {{False}} 6) {{False}} SKIP {{True}} 7) {{True}} WHILE True DO SKIP END {{False}} 8) {{X = 0}} WHILE X == 0 DO X ::= X + 1 END {{X = 1}} 9) {{X = 1}} WHILE X <> 0 DO X ::= X + 1 END {{X = 100}} *) (* FILL IN HERE *) (** [] *) (** (Note that we're using informal mathematical notations for expressions inside of commands, for readability, rather than their formal [aexp] and [bexp] encodings. We'll continue doing so throughout the chapter.) *) (** To get us warmed up for what's coming, here are two simple facts about Hoare triples. *) Theorem hoare_post_true : forall (P Q : Assertion) c, (forall st, Q st) -> {{P}} c {{Q}}. Proof. intros P Q c H. unfold hoare_triple. intros st st' Heval HP. apply H. Qed. Theorem hoare_pre_false : forall (P Q : Assertion) c, (forall st, ~(P st)) -> {{P}} c {{Q}}. Proof. intros P Q c H. unfold hoare_triple. intros st st' Heval HP. unfold not in H. apply H in HP. inversion HP. Qed. (* ####################################################### *) (** ** Proof Rules *) (** The goal of Hoare logic is to provide a _compositional_ method for proving the validity of Hoare triples. That is, the structure of a program's correctness proof should mirror the structure of the program itself. To this end, in the sections below, we'll introduce one rule for reasoning about each of the different syntactic forms of commands in Imp -- one for assignment, one for sequencing, one for conditionals, etc. -- plus a couple of "structural" rules that are useful for gluing things together. We will prove programs correct using these proof rules, without ever unfolding the definition of [hoare_triple]. *) (* ####################################################### *) (** *** Assignment *) (** The rule for assignment is the most fundamental of the Hoare logic proof rules. Here's how it works. Consider this (valid) Hoare triple: {{ Y = 1 }} X ::= Y {{ X = 1 }} In English: if we start out in a state where the value of [Y] is [1] and we assign [Y] to [X], then we'll finish in a state where [X] is [1]. That is, the property of being equal to [1] gets transferred from [Y] to [X]. Similarly, in {{ Y + Z = 1 }} X ::= Y + Z {{ X = 1 }} the same property (being equal to one) gets transferred to [X] from the expression [Y + Z] on the right-hand side of the assignment. More generally, if [a] is _any_ arithmetic expression, then {{ a = 1 }} X ::= a {{ X = 1 }} is a valid Hoare triple. This can be made even more general. To conclude that an _arbitrary_ property [Q] holds after [X ::= a], we need to assume that [Q] holds before [X ::= a], but _with all occurrences of_ [X] replaced by [a] in [Q]. This leads to the Hoare rule for assignment {{ Q [X |-> a] }} X ::= a {{ Q }} where "[Q [X |-> a]]" is pronounced "[Q] where [a] is substituted for [X]". For example, these are valid applications of the assignment rule: {{ (X <= 5) [X |-> X + 1] i.e., X + 1 <= 5 }} X ::= X + 1 {{ X <= 5 }} {{ (X = 3) [X |-> 3] i.e., 3 = 3}} X ::= 3 {{ X = 3 }} {{ (0 <= X /\ X <= 5) [X |-> 3] i.e., (0 <= 3 /\ 3 <= 5)}} X ::= 3 {{ 0 <= X /\ X <= 5 }} *) (** To formalize the rule, we must first formalize the idea of "substituting an expression for an Imp variable in an assertion." That is, given a proposition [P], a variable [X], and an arithmetic expression [a], we want to derive another proposition [P'] that is just the same as [P] except that, wherever [P] mentions [X], [P'] should instead mention [a]. Since [P] is an arbitrary Coq proposition, we can't directly "edit" its text. Instead, we can achieve the effect we want by evaluating [P] in an updated state: *) Definition assn_sub X a P : Assertion := fun (st : state) => P (update st X (aeval st a)). Notation "P [ X |-> a ]" := (assn_sub X a P) (at level 10). (** That is, [P [X |-> a]] is an assertion [P'] that is just like [P] except that, wherever [P] looks up the variable [X] in the current state, [P'] instead uses the value of the expression [a]. To see how this works, let's calculate what happens with a couple of examples. First, suppose [P'] is [(X <= 5) [X |-> 3]] -- that is, more formally, [P'] is the Coq expression fun st => (fun st' => st' X <= 5) (update st X (aeval st (ANum 3))), which simplifies to fun st => (fun st' => st' X <= 5) (update st X 3) and further simplifies to fun st => ((update st X 3) X) <= 5) and by further simplification to fun st => (3 <= 5). That is, [P'] is the assertion that [3] is less than or equal to [5] (as expected). For a more interesting example, suppose [P'] is [(X <= 5) [X |-> X+1]]. Formally, [P'] is the Coq expression fun st => (fun st' => st' X <= 5) (update st X (aeval st (APlus (AId X) (ANum 1)))), which simplifies to fun st => (((update st X (aeval st (APlus (AId X) (ANum 1))))) X) <= 5 and further simplifies to fun st => (aeval st (APlus (AId X) (ANum 1))) <= 5. That is, [P'] is the assertion that [X+1] is at most [5]. *) (** Now we can give the precise proof rule for assignment: ------------------------------ (hoare_asgn) {{Q [X |-> a]}} X ::= a {{Q}} *) (** We can prove formally that this rule is indeed valid. *) Theorem hoare_asgn : forall Q X a, {{Q [X |-> a]}} (X ::= a) {{Q}}. Proof. unfold hoare_triple. intros Q X a st st' HE HQ. inversion HE. subst. unfold assn_sub in HQ. assumption. Qed. (** Here's a first formal proof using this rule. *) Example assn_sub_example : {{(fun st => st X = 3) [X |-> ANum 3]}} (X ::= (ANum 3)) {{fun st => st X = 3}}. Proof. apply hoare_asgn. Qed. (** **** Exercise: 2 stars (hoare_asgn_examples) *) (** Translate these informal Hoare triples... 1) {{ (X <= 5) [X |-> X + 1] }} X ::= X + 1 {{ X <= 5 }} 2) {{ (0 <= X /\ X <= 5) [X |-> 3] }} X ::= 3 {{ 0 <= X /\ X <= 5 }} ...into formal statements [assn_sub_ex1, assn_sub_ex2] and use [hoare_asgn] to prove them. *) (* FILL IN HERE *) (** [] *) (** **** Exercise: 2 stars (hoare_asgn_wrong) *) (** The assignment rule looks backward to almost everyone the first time they see it. If it still seems backward to you, it may help to think a little about alternative "forward" rules. Here is a seemingly natural one: ------------------------------ (hoare_asgn_wrong) {{ True }} X ::= a {{ X = a }} Give a counterexample showing that this rule is incorrect (informally). Hint: The rule universally quantifies over the arithmetic expression [a], and your counterexample needs to exhibit an [a] for which the rule doesn't work. *) (* FILL IN HERE *) (** [] *) (** **** Exercise: 3 stars, advanced (hoare_asgn_fwd) *) (** However, using an auxiliary variable [m] to remember the original value of [X] we can define a Hoare rule for assignment that does, intuitively, "work forwards" rather than backwards. ------------------------------------------ (hoare_asgn_fwd) {{fun st => P st /\ st X = m}} X ::= a {{fun st => P st' /\ st X = aeval st' a }} (where st' = update st X m) Note that we use the original value of [X] to reconstruct the state [st'] before the assignment took place. Prove that this rule is correct (the first hypothesis is the functional extensionality axiom, which you will need at some point). Also note that this rule is more complicated than [hoare_asgn]. *) Theorem hoare_asgn_fwd : (forall {X Y: Type} {f g : X -> Y}, (forall (x: X), f x = g x) -> f = g) -> forall m a P, {{fun st => P st /\ st X = m}} X ::= a {{fun st => P (update st X m) /\ st X = aeval (update st X m) a }}. Proof. intros functional_extensionality m a P. (* FILL IN HERE *) Admitted. (** [] *) (** **** Exercise: 2 stars, advanced (hoare_asgn_fwd_exists) *) (** Another way to define a forward rule for assignment is to existentially quantify over the previous value of the assigned variable. ------------------------------------------ (hoare_asgn_fwd_exists) {{fun st => P st}} X ::= a {{fun st => exists m, P (update st X m) /\ st X = aeval (update st X m) a }} *) (* This rule was proposed by Nick Giannarakis and Zoe Paraskevopoulou. *) Theorem hoare_asgn_fwd_exists : (forall {X Y: Type} {f g : X -> Y}, (forall (x: X), f x = g x) -> f = g) -> forall a P, {{fun st => P st}} X ::= a {{fun st => exists m, P (update st X m) /\ st X = aeval (update st X m) a }}. Proof. intros functional_extensionality a P. (* FILL IN HERE *) Admitted. (** [] *) (* ####################################################### *) (** *** Consequence *) (** Sometimes the preconditions and postconditions we get from the Hoare rules won't quite be the ones we want in the particular situation at hand -- they may be logically equivalent but have a different syntactic form that fails to unify with the goal we are trying to prove, or they actually may be logically weaker (for preconditions) or stronger (for postconditions) than what we need. For instance, while {{(X = 3) [X |-> 3]}} X ::= 3 {{X = 3}}, follows directly from the assignment rule, {{True}} X ::= 3 {{X = 3}}. does not. This triple is valid, but it is not an instance of [hoare_asgn] because [True] and [(X = 3) [X |-> 3]] are not syntactically equal assertions. However, they are logically equivalent, so if one triple is valid, then the other must certainly be as well. We might capture this observation with the following rule: {{P'}} c {{Q}} P <<->> P' ----------------------------- (hoare_consequence_pre_equiv) {{P}} c {{Q}} Taking this line of thought a bit further, we can see that strengthening the precondition or weakening the postcondition of a valid triple always produces another valid triple. This observation is captured by two _Rules of Consequence_. {{P'}} c {{Q}} P ->> P' ----------------------------- (hoare_consequence_pre) {{P}} c {{Q}} {{P}} c {{Q'}} Q' ->> Q ----------------------------- (hoare_consequence_post) {{P}} c {{Q}} *) (** Here are the formal versions: *) Theorem hoare_consequence_pre : forall (P P' Q : Assertion) c, {{P'}} c {{Q}} -> P ->> P' -> {{P}} c {{Q}}. Proof. intros P P' Q c Hhoare Himp. intros st st' Hc HP. apply (Hhoare st st'). assumption. apply Himp. assumption. Qed. Theorem hoare_consequence_post : forall (P Q Q' : Assertion) c, {{P}} c {{Q'}} -> Q' ->> Q -> {{P}} c {{Q}}. Proof. intros P Q Q' c Hhoare Himp. intros st st' Hc HP. apply Himp. apply (Hhoare st st'). assumption. assumption. Qed. (** For example, we might use the first consequence rule like this: {{ True }} ->> {{ 1 = 1 }} X ::= 1 {{ X = 1 }} Or, formally... *) Example hoare_asgn_example1 : {{fun st => True}} (X ::= (ANum 1)) {{fun st => st X = 1}}. Proof. apply hoare_consequence_pre with (P' := (fun st => st X = 1) [X |-> ANum 1]). apply hoare_asgn. intros st H. unfold assn_sub, update. simpl. reflexivity. Qed. (** Finally, for convenience in some proofs, we can state a "combined" rule of consequence that allows us to vary both the precondition and the postcondition. {{P'}} c {{Q'}} P ->> P' Q' ->> Q ----------------------------- (hoare_consequence) {{P}} c {{Q}} *) Theorem hoare_consequence : forall (P P' Q Q' : Assertion) c, {{P'}} c {{Q'}} -> P ->> P' -> Q' ->> Q -> {{P}} c {{Q}}. Proof. intros P P' Q Q' c Hht HPP' HQ'Q. apply hoare_consequence_pre with (P' := P'). apply hoare_consequence_post with (Q' := Q'). assumption. assumption. assumption. Qed. (* ####################################################### *) (** *** Digression: The [eapply] Tactic *) (** This is a good moment to introduce another convenient feature of Coq. We had to write "[with (P' := ...)]" explicitly in the proof of [hoare_asgn_example1] and [hoare_consequence] above, to make sure that all of the metavariables in the premises to the [hoare_consequence_pre] rule would be set to specific values. (Since [P'] doesn't appear in the conclusion of [hoare_consequence_pre], the process of unifying the conclusion with the current goal doesn't constrain [P'] to a specific assertion.) This is a little annoying, both because the assertion is a bit long and also because for [hoare_asgn_example1] the very next thing we are going to do -- applying the [hoare_asgn] rule -- will tell us exactly what it should be! We can use [eapply] instead of [apply] to tell Coq, essentially, "Be patient: The missing part is going to be filled in soon." *) Example hoare_asgn_example1' : {{fun st => True}} (X ::= (ANum 1)) {{fun st => st X = 1}}. Proof. eapply hoare_consequence_pre. apply hoare_asgn. intros st H. reflexivity. Qed. (** In general, [eapply H] tactic works just like [apply H] except that, instead of failing if unifying the goal with the conclusion of [H] does not determine how to instantiate all of the variables appearing in the premises of [H], [eapply H] will replace these variables with so-called _existential variables_ (written [?nnn]) as placeholders for expressions that will be determined (by further unification) later in the proof. *) (** In order for [Qed] to succeed, all existential variables need to be determined by the end of the proof. Otherwise Coq will (rightly) refuse to accept the proof. Remember that the Coq tactics build proof objects, and proof objects containing existential variables are not complete. *) Lemma silly1 : forall (P : nat -> nat -> Prop) (Q : nat -> Prop), (forall x y : nat, P x y) -> (forall x y : nat, P x y -> Q x) -> Q 42. Proof. intros P Q HP HQ. eapply HQ. apply HP. (** Coq gives a warning after [apply HP]: No more subgoals but non-instantiated existential variables: Existential 1 = ?171 : [P : nat -> nat -> Prop Q : nat -> Prop HP : forall x y : nat, P x y HQ : forall x y : nat, P x y -> Q x |- nat] (dependent evars: ?171 open,) You can use Grab Existential Variables. Trying to finish the proof with [Qed] gives an error: << Error: Attempt to save a proof with existential variables still non-instantiated >> *) Abort. (** An additional constraint is that existential variables cannot be instantiated with terms containing (ordinary) variables that did not exist at the time the existential variable was created. *) Lemma silly2 : forall (P : nat -> nat -> Prop) (Q : nat -> Prop), (exists y, P 42 y) -> (forall x y : nat, P x y -> Q x) -> Q 42. Proof. intros P Q HP HQ. eapply HQ. destruct HP as [y HP']. (** Doing [apply HP'] above fails with the following error: Error: Impossible to unify "?175" with "y". In this case there is an easy fix: doing [destruct HP] _before_ doing [eapply HQ]. *) Abort. Lemma silly2_fixed : forall (P : nat -> nat -> Prop) (Q : nat -> Prop), (exists y, P 42 y) -> (forall x y : nat, P x y -> Q x) -> Q 42. Proof. intros P Q HP HQ. destruct HP as [y HP']. eapply HQ. apply HP'. Qed. (** In the last step we did [apply HP'] which unifies the existential variable in the goal with the variable [y]. The [assumption] tactic doesn't work in this case, since it cannot handle existential variables. However, Coq also provides an [eassumption] tactic that solves the goal if one of the premises matches the goal up to instantiations of existential variables. We can use it instead of [apply HP']. *) Lemma silly2_eassumption : forall (P : nat -> nat -> Prop) (Q : nat -> Prop), (exists y, P 42 y) -> (forall x y : nat, P x y -> Q x) -> Q 42. Proof. intros P Q HP HQ. destruct HP as [y HP']. eapply HQ. eassumption. Qed. (** **** Exercise: 2 stars (hoare_asgn_examples_2) *) (** Translate these informal Hoare triples... {{ X + 1 <= 5 }} X ::= X + 1 {{ X <= 5 }} {{ 0 <= 3 /\ 3 <= 5 }} X ::= 3 {{ 0 <= X /\ X <= 5 }} ...into formal statements [assn_sub_ex1', assn_sub_ex2'] and use [hoare_asgn] and [hoare_consequence_pre] to prove them. *) (* FILL IN HERE *) (** [] *) (* ####################################################### *) (** *** Skip *) (** Since [SKIP] doesn't change the state, it preserves any property P: -------------------- (hoare_skip) {{ P }} SKIP {{ P }} *) Theorem hoare_skip : forall P, {{P}} SKIP {{P}}. Proof. intros P st st' H HP. inversion H. subst. assumption. Qed. (* ####################################################### *) (** *** Sequencing *) (** More interestingly, if the command [c1] takes any state where [P] holds to a state where [Q] holds, and if [c2] takes any state where [Q] holds to one where [R] holds, then doing [c1] followed by [c2] will take any state where [P] holds to one where [R] holds: {{ P }} c1 {{ Q }} {{ Q }} c2 {{ R }} --------------------- (hoare_seq) {{ P }} c1;;c2 {{ R }} *) Theorem hoare_seq : forall P Q R c1 c2, {{Q}} c2 {{R}} -> {{P}} c1 {{Q}} -> {{P}} c1;;c2 {{R}}. Proof. intros P Q R c1 c2 H1 H2 st st' H12 Pre. inversion H12; subst. apply (H1 st'0 st'); try assumption. apply (H2 st st'0); assumption. Qed. (** Note that, in the formal rule [hoare_seq], the premises are given in "backwards" order ([c2] before [c1]). This matches the natural flow of information in many of the situations where we'll use the rule: the natural way to construct a Hoare-logic proof is to begin at the end of the program (with the final postcondition) and push postconditions backwards through commands until we reach the beginning. *) (** Informally, a nice way of recording a proof using the sequencing rule is as a "decorated program" where the intermediate assertion [Q] is written between [c1] and [c2]: {{ a = n }} X ::= a;; {{ X = n }} <---- decoration for Q SKIP {{ X = n }} *) Example hoare_asgn_example3 : forall a n, {{fun st => aeval st a = n}} (X ::= a;; SKIP) {{fun st => st X = n}}. Proof. intros a n. eapply hoare_seq. Case "right part of seq". apply hoare_skip. Case "left part of seq". eapply hoare_consequence_pre. apply hoare_asgn. intros st H. subst. reflexivity. Qed. (** You will most often use [hoare_seq] and [hoare_consequence_pre] in conjunction with the [eapply] tactic, as done above. *) (** **** Exercise: 2 stars (hoare_asgn_example4) *) (** Translate this "decorated program" into a formal proof: {{ True }} ->> {{ 1 = 1 }} X ::= 1;; {{ X = 1 }} ->> {{ X = 1 /\ 2 = 2 }} Y ::= 2 {{ X = 1 /\ Y = 2 }} *) Example hoare_asgn_example4 : {{fun st => True}} (X ::= (ANum 1);; Y ::= (ANum 2)) {{fun st => st X = 1 /\ st Y = 2}}. Proof. (* FILL IN HERE *) Admitted. (** [] *) (** **** Exercise: 3 stars (swap_exercise) *) (** Write an Imp program [c] that swaps the values of [X] and [Y] and show (in Coq) that it satisfies the following specification: {{X <= Y}} c {{Y <= X}} *) Definition swap_program : com := (* FILL IN HERE *) admit. Theorem swap_exercise : {{fun st => st X <= st Y}} swap_program {{fun st => st Y <= st X}}. Proof. (* FILL IN HERE *) Admitted. (** [] *) (** **** Exercise: 3 stars (hoarestate1) *) (** Explain why the following proposition can't be proven: forall (a : aexp) (n : nat), {{fun st => aeval st a = n}} (X ::= (ANum 3);; Y ::= a) {{fun st => st Y = n}}. *) (* FILL IN HERE *) (** [] *) (* ####################################################### *) (** *** Conditionals *) (** What sort of rule do we want for reasoning about conditional commands? Certainly, if the same assertion [Q] holds after executing either branch, then it holds after the whole conditional. So we might be tempted to write: {{P}} c1 {{Q}} {{P}} c2 {{Q}} -------------------------------- {{P}} IFB b THEN c1 ELSE c2 {{Q}} However, this is rather weak. For example, using this rule, we cannot show that: {{ True }} IFB X == 0 THEN Y ::= 2 ELSE Y ::= X + 1 FI {{ X <= Y }} since the rule tells us nothing about the state in which the assignments take place in the "then" and "else" branches. *) (** But we can actually say something more precise. In the "then" branch, we know that the boolean expression [b] evaluates to [true], and in the "else" branch, we know it evaluates to [false]. Making this information available in the premises of the rule gives us more information to work with when reasoning about the behavior of [c1] and [c2] (i.e., the reasons why they establish the postcondition [Q]). *) (** {{P /\ b}} c1 {{Q}} {{P /\ ~b}} c2 {{Q}} ------------------------------------ (hoare_if) {{P}} IFB b THEN c1 ELSE c2 FI {{Q}} *) (** To interpret this rule formally, we need to do a little work. Strictly speaking, the assertion we've written, [P /\ b], is the conjunction of an assertion and a boolean expression -- i.e., it doesn't typecheck. To fix this, we need a way of formally "lifting" any bexp [b] to an assertion. We'll write [bassn b] for the assertion "the boolean expression [b] evaluates to [true] (in the given state)." *) Definition bassn b : Assertion := fun st => (beval st b = true). (** A couple of useful facts about [bassn]: *) Lemma bexp_eval_true : forall b st, beval st b = true -> (bassn b) st. Proof. intros b st Hbe. unfold bassn. assumption. Qed. Lemma bexp_eval_false : forall b st, beval st b = false -> ~ ((bassn b) st). Proof. intros b st Hbe contra. unfold bassn in contra. rewrite -> contra in Hbe. inversion Hbe. Qed. (** Now we can formalize the Hoare proof rule for conditionals and prove it correct. *) Theorem hoare_if : forall P Q b c1 c2, {{fun st => P st /\ bassn b st}} c1 {{Q}} -> {{fun st => P st /\ ~(bassn b st)}} c2 {{Q}} -> {{P}} (IFB b THEN c1 ELSE c2 FI) {{Q}}. Proof. intros P Q b c1 c2 HTrue HFalse st st' HE HP. inversion HE; subst. Case "b is true". apply (HTrue st st'). assumption. split. assumption. apply bexp_eval_true. assumption. Case "b is false". apply (HFalse st st'). assumption. split. assumption. apply bexp_eval_false. assumption. Qed. (* ####################################################### *) (** * Hoare Logic: So Far *) (** Idea: create a _domain specific logic_ for reasoning about properties of Imp programs. - This hides the low-level details of the semantics of the program - Leads to a compositional reasoning process The basic structure is given by _Hoare triples_ of the form: {{P}} c {{Q}} ]] - [P] and [Q] are predicates about the state of the Imp program - "If command [c] is started in a state satisfying assertion [P], and if [c] eventually terminates in some final state, then this final state will satisfy the assertion [Q]." *) (** ** Hoare Logic Rules (so far) *) (** ------------------------------ (hoare_asgn) {{Q [X |-> a]}} X::=a {{Q}} -------------------- (hoare_skip) {{ P }} SKIP {{ P }} {{ P }} c1 {{ Q }} {{ Q }} c2 {{ R }} --------------------- (hoare_seq) {{ P }} c1;;c2 {{ R }} {{P /\ b}} c1 {{Q}} {{P /\ ~b}} c2 {{Q}} ------------------------------------ (hoare_if) {{P}} IFB b THEN c1 ELSE c2 FI {{Q}} {{P'}} c {{Q'}} P ->> P' Q' ->> Q ----------------------------- (hoare_consequence) {{P}} c {{Q}} *) (** *** Example *) (** Here is a formal proof that the program we used to motivate the rule satisfies the specification we gave. *) Example if_example : {{fun st => True}} IFB (BEq (AId X) (ANum 0)) THEN (Y ::= (ANum 2)) ELSE (Y ::= APlus (AId X) (ANum 1)) FI {{fun st => st X <= st Y}}. Proof. (* WORKED IN CLASS *) apply hoare_if. Case "Then". eapply hoare_consequence_pre. apply hoare_asgn. unfold bassn, assn_sub, update, assert_implies. simpl. intros st [_ H]. apply beq_nat_true in H. rewrite H. omega. Case "Else". eapply hoare_consequence_pre. apply hoare_asgn. unfold assn_sub, update, assert_implies. simpl; intros st _. omega. Qed. (** **** Exercise: 2 stars (if_minus_plus) *) (** Prove the following hoare triple using [hoare_if]: *) Theorem if_minus_plus : {{fun st => True}} IFB (BLe (AId X) (AId Y)) THEN (Z ::= AMinus (AId Y) (AId X)) ELSE (Y ::= APlus (AId X) (AId Z)) FI {{fun st => st Y = st X + st Z}}. Proof. (* FILL IN HERE *) Admitted. (* ####################################################### *) (** *** Exercise: One-sided conditionals *) (** **** Exercise: 4 stars (if1_hoare) *) (** In this exercise we consider extending Imp with "one-sided conditionals" of the form [IF1 b THEN c FI]. Here [b] is a boolean expression, and [c] is a command. If [b] evaluates to [true], then command [c] is evaluated. If [b] evaluates to [false], then [IF1 b THEN c FI] does nothing. We recommend that you do this exercise before the ones that follow, as it should help solidify your understanding of the material. *) (** The first step is to extend the syntax of commands and introduce the usual notations. (We've done this for you. We use a separate module to prevent polluting the global name space.) *) Module If1. Inductive com : Type := | CSkip : com | CAss : id -> aexp -> com | CSeq : com -> com -> com | CIf : bexp -> com -> com -> com | CWhile : bexp -> com -> com | CIf1 : bexp -> com -> com. Tactic Notation "com_cases" tactic(first) ident(c) := first; [ Case_aux c "SKIP" | Case_aux c "::=" | Case_aux c ";" | Case_aux c "IFB" | Case_aux c "WHILE" | Case_aux c "CIF1" ]. Notation "'SKIP'" := CSkip. Notation "c1 ;; c2" := (CSeq c1 c2) (at level 80, right associativity). Notation "X '::=' a" := (CAss X a) (at level 60). Notation "'WHILE' b 'DO' c 'END'" := (CWhile b c) (at level 80, right associativity). Notation "'IFB' e1 'THEN' e2 'ELSE' e3 'FI'" := (CIf e1 e2 e3) (at level 80, right associativity). Notation "'IF1' b 'THEN' c 'FI'" := (CIf1 b c) (at level 80, right associativity). (** Next we need to extend the evaluation relation to accommodate [IF1] branches. This is for you to do... What rule(s) need to be added to [ceval] to evaluate one-sided conditionals? *) Reserved Notation "c1 '/' st '||' st'" (at level 40, st at level 39). Inductive ceval : com -> state -> state -> Prop := | E_Skip : forall st : state, SKIP / st || st | E_Ass : forall (st : state) (a1 : aexp) (n : nat) (X : id), aeval st a1 = n -> (X ::= a1) / st || update st X n | E_Seq : forall (c1 c2 : com) (st st' st'' : state), c1 / st || st' -> c2 / st' || st'' -> (c1 ;; c2) / st || st'' | E_IfTrue : forall (st st' : state) (b1 : bexp) (c1 c2 : com), beval st b1 = true -> c1 / st || st' -> (IFB b1 THEN c1 ELSE c2 FI) / st || st' | E_IfFalse : forall (st st' : state) (b1 : bexp) (c1 c2 : com), beval st b1 = false -> c2 / st || st' -> (IFB b1 THEN c1 ELSE c2 FI) / st || st' | E_WhileEnd : forall (b1 : bexp) (st : state) (c1 : com), beval st b1 = false -> (WHILE b1 DO c1 END) / st || st | E_WhileLoop : forall (st st' st'' : state) (b1 : bexp) (c1 : com), beval st b1 = true -> c1 / st || st' -> (WHILE b1 DO c1 END) / st' || st'' -> (WHILE b1 DO c1 END) / st || st'' (* FILL IN HERE *) where "c1 '/' st '||' st'" := (ceval c1 st st'). Tactic Notation "ceval_cases" tactic(first) ident(c) := first; [ Case_aux c "E_Skip" | Case_aux c "E_Ass" | Case_aux c "E_Seq" | Case_aux c "E_IfTrue" | Case_aux c "E_IfFalse" | Case_aux c "E_WhileEnd" | Case_aux c "E_WhileLoop" (* FILL IN HERE *) ]. (** Now we repeat (verbatim) the definition and notation of Hoare triples. *) Definition hoare_triple (P:Assertion) (c:com) (Q:Assertion) : Prop := forall st st', c / st || st' -> P st -> Q st'. Notation "{{ P }} c {{ Q }}" := (hoare_triple P c Q) (at level 90, c at next level) : hoare_spec_scope. (** Finally, we (i.e., you) need to state and prove a theorem, [hoare_if1], that expresses an appropriate Hoare logic proof rule for one-sided conditionals. Try to come up with a rule that is both sound and as precise as possible. *) (* FILL IN HERE *) (** For full credit, prove formally [hoare_if1_good] that your rule is precise enough to show the following valid Hoare triple: {{ X + Y = Z }} IF1 Y <> 0 THEN X ::= X + Y FI {{ X = Z }} *) (** Hint: Your proof of this triple may need to use the other proof rules also. Because we're working in a separate module, you'll need to copy here the rules you find necessary. *) Lemma hoare_if1_good : {{ fun st => st X + st Y = st Z }} IF1 BNot (BEq (AId Y) (ANum 0)) THEN X ::= APlus (AId X) (AId Y) FI {{ fun st => st X = st Z }}. Proof. (* FILL IN HERE *) Admitted. End If1. (** [] *) (* ####################################################### *) (** *** Loops *) (** Finally, we need a rule for reasoning about while loops. *) (** Suppose we have a loop WHILE b DO c END and we want to find a pre-condition [P] and a post-condition [Q] such that {{P}} WHILE b DO c END {{Q}} is a valid triple. *) (** *** *) (** First of all, let's think about the case where [b] is false at the beginning -- i.e., let's assume that the loop body never executes at all. In this case, the loop behaves like [SKIP], so we might be tempted to write: *) (** {{P}} WHILE b DO c END {{P}}. *) (** But, as we remarked above for the conditional, we know a little more at the end -- not just [P], but also the fact that [b] is false in the current state. So we can enrich the postcondition a little: *) (** {{P}} WHILE b DO c END {{P /\ ~b}} *) (** What about the case where the loop body _does_ get executed? In order to ensure that [P] holds when the loop finally exits, we certainly need to make sure that the command [c] guarantees that [P] holds whenever [c] is finished. Moreover, since [P] holds at the beginning of the first execution of [c], and since each execution of [c] re-establishes [P] when it finishes, we can always assume that [P] holds at the beginning of [c]. This leads us to the following rule: *) (** {{P}} c {{P}} ----------------------------------- {{P}} WHILE b DO c END {{P /\ ~b}} *) (** This is almost the rule we want, but again it can be improved a little: at the beginning of the loop body, we know not only that [P] holds, but also that the guard [b] is true in the current state. This gives us a little more information to use in reasoning about [c] (showing that it establishes the invariant by the time it finishes). This gives us the final version of the rule: *) (** {{P /\ b}} c {{P}} ----------------------------------- (hoare_while) {{P}} WHILE b DO c END {{P /\ ~b}} The proposition [P] is called an _invariant_ of the loop. *) Lemma hoare_while : forall P b c, {{fun st => P st /\ bassn b st}} c {{P}} -> {{P}} WHILE b DO c END {{fun st => P st /\ ~ (bassn b st)}}. Proof. intros P b c Hhoare st st' He HP. (* Like we've seen before, we need to reason by induction on [He], because, in the "keep looping" case, its hypotheses talk about the whole loop instead of just [c]. *) remember (WHILE b DO c END) as wcom eqn:Heqwcom. ceval_cases (induction He) Case; try (inversion Heqwcom); subst; clear Heqwcom. Case "E_WhileEnd". split. assumption. apply bexp_eval_false. assumption. Case "E_WhileLoop". apply IHHe2. reflexivity. apply (Hhoare st st'). assumption. split. assumption. apply bexp_eval_true. assumption. Qed. (** One subtlety in the terminology is that calling some assertion [P] a "loop invariant" doesn't just mean that it is preserved by the body of the loop in question (i.e., [{{P}} c {{P}}], where [c] is the loop body), but rather that [P] _together with the fact that the loop's guard is true_ is a sufficient precondition for [c] to ensure [P] as a postcondition. This is a slightly (but significantly) weaker requirement. For example, if [P] is the assertion [X = 0], then [P] _is_ an invariant of the loop WHILE X = 2 DO X := 1 END although it is clearly _not_ preserved by the body of the loop. *) Example while_example : {{fun st => st X <= 3}} WHILE (BLe (AId X) (ANum 2)) DO X ::= APlus (AId X) (ANum 1) END {{fun st => st X = 3}}. Proof. eapply hoare_consequence_post. apply hoare_while. eapply hoare_consequence_pre. apply hoare_asgn. unfold bassn, assn_sub, assert_implies, update. simpl. intros st [H1 H2]. apply ble_nat_true in H2. omega. unfold bassn, assert_implies. intros st [Hle Hb]. simpl in Hb. destruct (ble_nat (st X) 2) eqn : Heqle. apply ex_falso_quodlibet. apply Hb; reflexivity. apply ble_nat_false in Heqle. omega. Qed. (** *** *) (** We can use the while rule to prove the following Hoare triple, which may seem surprising at first... *) Theorem always_loop_hoare : forall P Q, {{P}} WHILE BTrue DO SKIP END {{Q}}. Proof. (* WORKED IN CLASS *) intros P Q. apply hoare_consequence_pre with (P' := fun st : state => True). eapply hoare_consequence_post. apply hoare_while. Case "Loop body preserves invariant". apply hoare_post_true. intros st. apply I. Case "Loop invariant and negated guard imply postcondition". simpl. intros st [Hinv Hguard]. apply ex_falso_quodlibet. apply Hguard. reflexivity. Case "Precondition implies invariant". intros st H. constructor. Qed. (** Of course, this result is not surprising if we remember that the definition of [hoare_triple] asserts that the postcondition must hold _only_ when the command terminates. If the command doesn't terminate, we can prove anything we like about the post-condition. *) (** Hoare rules that only talk about terminating commands are often said to describe a logic of "partial" correctness. It is also possible to give Hoare rules for "total" correctness, which build in the fact that the commands terminate. However, in this course we will only talk about partial correctness. *) (* ####################################################### *) (** *** Exercise: [REPEAT] *) Module RepeatExercise. (** **** Exercise: 4 stars, advanced (hoare_repeat) *) (** In this exercise, we'll add a new command to our language of commands: [REPEAT] c [UNTIL] a [END]. You will write the evaluation rule for [repeat] and add a new Hoare rule to the language for programs involving it. *) Inductive com : Type := | CSkip : com | CAsgn : id -> aexp -> com | CSeq : com -> com -> com | CIf : bexp -> com -> com -> com | CWhile : bexp -> com -> com | CRepeat : com -> bexp -> com. (** [REPEAT] behaves like [WHILE], except that the loop guard is checked _after_ each execution of the body, with the loop repeating as long as the guard stays _false_. Because of this, the body will always execute at least once. *) Tactic Notation "com_cases" tactic(first) ident(c) := first; [ Case_aux c "SKIP" | Case_aux c "::=" | Case_aux c ";" | Case_aux c "IFB" | Case_aux c "WHILE" | Case_aux c "CRepeat" ]. Notation "'SKIP'" := CSkip. Notation "c1 ;; c2" := (CSeq c1 c2) (at level 80, right associativity). Notation "X '::=' a" := (CAsgn X a) (at level 60). Notation "'WHILE' b 'DO' c 'END'" := (CWhile b c) (at level 80, right associativity). Notation "'IFB' e1 'THEN' e2 'ELSE' e3 'FI'" := (CIf e1 e2 e3) (at level 80, right associativity). Notation "'REPEAT' e1 'UNTIL' b2 'END'" := (CRepeat e1 b2) (at level 80, right associativity). (** Add new rules for [REPEAT] to [ceval] below. You can use the rules for [WHILE] as a guide, but remember that the body of a [REPEAT] should always execute at least once, and that the loop ends when the guard becomes true. Then update the [ceval_cases] tactic to handle these added cases. *) Inductive ceval : state -> com -> state -> Prop := | E_Skip : forall st, ceval st SKIP st | E_Ass : forall st a1 n X, aeval st a1 = n -> ceval st (X ::= a1) (update st X n) | E_Seq : forall c1 c2 st st' st'', ceval st c1 st' -> ceval st' c2 st'' -> ceval st (c1 ;; c2) st'' | E_IfTrue : forall st st' b1 c1 c2, beval st b1 = true -> ceval st c1 st' -> ceval st (IFB b1 THEN c1 ELSE c2 FI) st' | E_IfFalse : forall st st' b1 c1 c2, beval st b1 = false -> ceval st c2 st' -> ceval st (IFB b1 THEN c1 ELSE c2 FI) st' | E_WhileEnd : forall b1 st c1, beval st b1 = false -> ceval st (WHILE b1 DO c1 END) st | E_WhileLoop : forall st st' st'' b1 c1, beval st b1 = true -> ceval st c1 st' -> ceval st' (WHILE b1 DO c1 END) st'' -> ceval st (WHILE b1 DO c1 END) st'' (* FILL IN HERE *) . Tactic Notation "ceval_cases" tactic(first) ident(c) := first; [ Case_aux c "E_Skip" | Case_aux c "E_Ass" | Case_aux c "E_Seq" | Case_aux c "E_IfTrue" | Case_aux c "E_IfFalse" | Case_aux c "E_WhileEnd" | Case_aux c "E_WhileLoop" (* FILL IN HERE *) ]. (** A couple of definitions from above, copied here so they use the new [ceval]. *) Notation "c1 '/' st '||' st'" := (ceval st c1 st') (at level 40, st at level 39). Definition hoare_triple (P:Assertion) (c:com) (Q:Assertion) : Prop := forall st st', (c / st || st') -> P st -> Q st'. Notation "{{ P }} c {{ Q }}" := (hoare_triple P c Q) (at level 90, c at next level). (** To make sure you've got the evaluation rules for [REPEAT] right, prove that [ex1_repeat evaluates correctly. *) Definition ex1_repeat := REPEAT X ::= ANum 1;; Y ::= APlus (AId Y) (ANum 1) UNTIL (BEq (AId X) (ANum 1)) END. Theorem ex1_repeat_works : ex1_repeat / empty_state || update (update empty_state X 1) Y 1. Proof. (* FILL IN HERE *) Admitted. (** Now state and prove a theorem, [hoare_repeat], that expresses an appropriate proof rule for [repeat] commands. Use [hoare_while] as a model, and try to make your rule as precise as possible. *) (* FILL IN HERE *) (** For full credit, make sure (informally) that your rule can be used to prove the following valid Hoare triple: {{ X > 0 }} REPEAT Y ::= X;; X ::= X - 1 UNTIL X = 0 END {{ X = 0 /\ Y > 0 }} *) End RepeatExercise. (** [] *) (* ####################################################### *) (** ** Exercise: [HAVOC] *) (** **** Exercise: 3 stars (himp_hoare) *) (** In this exercise, we will derive proof rules for the [HAVOC] command which we studied in the last chapter. First, we enclose this work in a separate module, and recall the syntax and big-step semantics of Himp commands. *) Module Himp. Inductive com : Type := | CSkip : com | CAsgn : id -> aexp -> com | CSeq : com -> com -> com | CIf : bexp -> com -> com -> com | CWhile : bexp -> com -> com | CHavoc : id -> com. Tactic Notation "com_cases" tactic(first) ident(c) := first; [ Case_aux c "SKIP" | Case_aux c "::=" | Case_aux c ";" | Case_aux c "IFB" | Case_aux c "WHILE" | Case_aux c "HAVOC" ]. Notation "'SKIP'" := CSkip. Notation "X '::=' a" := (CAsgn X a) (at level 60). Notation "c1 ;; c2" := (CSeq c1 c2) (at level 80, right associativity). Notation "'WHILE' b 'DO' c 'END'" := (CWhile b c) (at level 80, right associativity). Notation "'IFB' e1 'THEN' e2 'ELSE' e3 'FI'" := (CIf e1 e2 e3) (at level 80, right associativity). Notation "'HAVOC' X" := (CHavoc X) (at level 60). Reserved Notation "c1 '/' st '||' st'" (at level 40, st at level 39). Inductive ceval : com -> state -> state -> Prop := | E_Skip : forall st : state, SKIP / st || st | E_Ass : forall (st : state) (a1 : aexp) (n : nat) (X : id), aeval st a1 = n -> (X ::= a1) / st || update st X n | E_Seq : forall (c1 c2 : com) (st st' st'' : state), c1 / st || st' -> c2 / st' || st'' -> (c1 ;; c2) / st || st'' | E_IfTrue : forall (st st' : state) (b1 : bexp) (c1 c2 : com), beval st b1 = true -> c1 / st || st' -> (IFB b1 THEN c1 ELSE c2 FI) / st || st' | E_IfFalse : forall (st st' : state) (b1 : bexp) (c1 c2 : com), beval st b1 = false -> c2 / st || st' -> (IFB b1 THEN c1 ELSE c2 FI) / st || st' | E_WhileEnd : forall (b1 : bexp) (st : state) (c1 : com), beval st b1 = false -> (WHILE b1 DO c1 END) / st || st | E_WhileLoop : forall (st st' st'' : state) (b1 : bexp) (c1 : com), beval st b1 = true -> c1 / st || st' -> (WHILE b1 DO c1 END) / st' || st'' -> (WHILE b1 DO c1 END) / st || st'' | E_Havoc : forall (st : state) (X : id) (n : nat), (HAVOC X) / st || update st X n where "c1 '/' st '||' st'" := (ceval c1 st st'). Tactic Notation "ceval_cases" tactic(first) ident(c) := first; [ Case_aux c "E_Skip" | Case_aux c "E_Ass" | Case_aux c "E_Seq" | Case_aux c "E_IfTrue" | Case_aux c "E_IfFalse" | Case_aux c "E_WhileEnd" | Case_aux c "E_WhileLoop" | Case_aux c "E_Havoc" ]. (** The definition of Hoare triples is exactly as before. Unlike our notion of program equivalence, which had subtle consequences with occassionally nonterminating commands (exercise [havoc_diverge]), this definition is still fully satisfactory. Convince yourself of this before proceeding. *) Definition hoare_triple (P:Assertion) (c:com) (Q:Assertion) : Prop := forall st st', c / st || st' -> P st -> Q st'. Notation "{{ P }} c {{ Q }}" := (hoare_triple P c Q) (at level 90, c at next level) : hoare_spec_scope. (** Complete the Hoare rule for [HAVOC] commands below by defining [havoc_pre] and prove that the resulting rule is correct. *) Definition havoc_pre (X : id) (Q : Assertion) : Assertion := (* FILL IN HERE *) admit. Theorem hoare_havoc : forall (Q : Assertion) (X : id), {{ havoc_pre X Q }} HAVOC X {{ Q }}. Proof. (* FILL IN HERE *) Admitted. End Himp. (** [] *) (* ####################################################### *) (** ** Complete List of Hoare Logic Rules *) (** Above, we've introduced Hoare Logic as a tool to reasoning about Imp programs. In the reminder of this chapter we will explore a systematic way to use Hoare Logic to prove properties about programs. The rules of Hoare Logic are the following: *) (** ------------------------------ (hoare_asgn) {{Q [X |-> a]}} X::=a {{Q}} -------------------- (hoare_skip) {{ P }} SKIP {{ P }} {{ P }} c1 {{ Q }} {{ Q }} c2 {{ R }} --------------------- (hoare_seq) {{ P }} c1;;c2 {{ R }} {{P /\ b}} c1 {{Q}} {{P /\ ~b}} c2 {{Q}} ------------------------------------ (hoare_if) {{P}} IFB b THEN c1 ELSE c2 FI {{Q}} {{P /\ b}} c {{P}} ----------------------------------- (hoare_while) {{P}} WHILE b DO c END {{P /\ ~b}} {{P'}} c {{Q'}} P ->> P' Q' ->> Q ----------------------------- (hoare_consequence) {{P}} c {{Q}} In the next chapter, we'll see how these rules are used to prove that programs satisfy specifications of their behavior. *) (** $Date: 2014-12-31 11:17:56 -0500 (Wed, 31 Dec 2014) $ *)
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * 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. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // 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 REGENTS OF THE // UNIVERSITY OF CALIFORNIA 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. // ---------------------------------------------------------------------- `include "trellis.vh" `include "riffa.vh" `timescale 1ns/1ns module riffa #(parameter C_PCI_DATA_WIDTH = 128, parameter C_NUM_CHNL = 12, parameter C_MAX_READ_REQ_BYTES = 512, // Max size of read requests (in bytes) parameter C_TAG_WIDTH = 5, // Number of outstanding requests parameter C_VENDOR = "ALTERA", parameter C_FPGA_NAME = "FPGA", // TODO: Give each channel a unique name parameter C_FPGA_ID = 0,// A value from 0 to 255 uniquely identifying this RIFFA design parameter C_DEPTH_PACKETS = 10) (input CLK, input RST_BUS, output RST_OUT, input DONE_TXC_RST, input DONE_TXR_RST, // Interface: RXC Engine input [C_PCI_DATA_WIDTH-1:0] RXC_DATA, input RXC_DATA_VALID, input [(C_PCI_DATA_WIDTH/32)-1:0] RXC_DATA_WORD_ENABLE, input RXC_DATA_START_FLAG, input [clog2s(C_PCI_DATA_WIDTH/32)-1:0] RXC_DATA_START_OFFSET, input RXC_DATA_END_FLAG, input [clog2s(C_PCI_DATA_WIDTH/32)-1:0] RXC_DATA_END_OFFSET, input [`SIG_LBE_W-1:0] RXC_META_LDWBE, input [`SIG_FBE_W-1:0] RXC_META_FDWBE, input [`SIG_TAG_W-1:0] RXC_META_TAG, input [`SIG_LOWADDR_W-1:0] RXC_META_ADDR, input [`SIG_TYPE_W-1:0] RXC_META_TYPE, input [`SIG_LEN_W-1:0] RXC_META_LENGTH, input [`SIG_BYTECNT_W-1:0] RXC_META_BYTES_REMAINING, input [`SIG_CPLID_W-1:0] RXC_META_COMPLETER_ID, input RXC_META_EP, // Interface: RXR Engine input [C_PCI_DATA_WIDTH-1:0] RXR_DATA, input RXR_DATA_VALID, input [(C_PCI_DATA_WIDTH/32)-1:0] RXR_DATA_WORD_ENABLE, input RXR_DATA_START_FLAG, input [clog2s(C_PCI_DATA_WIDTH/32)-1:0] RXR_DATA_START_OFFSET, input RXR_DATA_END_FLAG, input [clog2s(C_PCI_DATA_WIDTH/32)-1:0] RXR_DATA_END_OFFSET, input [`SIG_FBE_W-1:0] RXR_META_FDWBE, input [`SIG_LBE_W-1:0] RXR_META_LDWBE, input [`SIG_TC_W-1:0] RXR_META_TC, input [`SIG_ATTR_W-1:0] RXR_META_ATTR, input [`SIG_TAG_W-1:0] RXR_META_TAG, input [`SIG_TYPE_W-1:0] RXR_META_TYPE, input [`SIG_ADDR_W-1:0] RXR_META_ADDR, input [`SIG_BARDECODE_W-1:0] RXR_META_BAR_DECODED, input [`SIG_REQID_W-1:0] RXR_META_REQUESTER_ID, input [`SIG_LEN_W-1:0] RXR_META_LENGTH, input RXR_META_EP, // Interface: TXC Engine output [C_PCI_DATA_WIDTH-1:0] TXC_DATA, output TXC_DATA_VALID, output TXC_DATA_START_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] TXC_DATA_START_OFFSET, output TXC_DATA_END_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] TXC_DATA_END_OFFSET, input TXC_DATA_READY, output TXC_META_VALID, output [`SIG_FBE_W-1:0] TXC_META_FDWBE, output [`SIG_LBE_W-1:0] TXC_META_LDWBE, output [`SIG_LOWADDR_W-1:0] TXC_META_ADDR, output [`SIG_TYPE_W-1:0] TXC_META_TYPE, output [`SIG_LEN_W-1:0] TXC_META_LENGTH, output [`SIG_BYTECNT_W-1:0] TXC_META_BYTE_COUNT, output [`SIG_TAG_W-1:0] TXC_META_TAG, output [`SIG_REQID_W-1:0] TXC_META_REQUESTER_ID, output [`SIG_TC_W-1:0] TXC_META_TC, output [`SIG_ATTR_W-1:0] TXC_META_ATTR, output TXC_META_EP, input TXC_META_READY, input TXC_SENT, // Interface: TXR Engine output TXR_DATA_VALID, output [C_PCI_DATA_WIDTH-1:0] TXR_DATA, output TXR_DATA_START_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] TXR_DATA_START_OFFSET, output TXR_DATA_END_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] TXR_DATA_END_OFFSET, input TXR_DATA_READY, output TXR_META_VALID, output [`SIG_FBE_W-1:0] TXR_META_FDWBE, output [`SIG_LBE_W-1:0] TXR_META_LDWBE, output [`SIG_ADDR_W-1:0] TXR_META_ADDR, output [`SIG_LEN_W-1:0] TXR_META_LENGTH, output [`SIG_TAG_W-1:0] TXR_META_TAG, output [`SIG_TC_W-1:0] TXR_META_TC, output [`SIG_ATTR_W-1:0] TXR_META_ATTR, output [`SIG_TYPE_W-1:0] TXR_META_TYPE, output TXR_META_EP, input TXR_META_READY, input TXR_SENT, // Interface: Configuration input [`SIG_CPLID_W-1:0] CONFIG_COMPLETER_ID, input CONFIG_BUS_MASTER_ENABLE, input [`SIG_LINKWIDTH_W-1:0] CONFIG_LINK_WIDTH, input [`SIG_LINKRATE_W-1:0] CONFIG_LINK_RATE, input [`SIG_MAXREAD_W-1:0] CONFIG_MAX_READ_REQUEST_SIZE, input [`SIG_MAXPAYLOAD_W-1:0] CONFIG_MAX_PAYLOAD_SIZE, input [`SIG_FC_CPLD_W-1:0] CONFIG_MAX_CPL_DATA, // Receive credit limit for data input [`SIG_FC_CPLH_W-1:0] CONFIG_MAX_CPL_HDR, // Receive credit limit for headers input CONFIG_INTERRUPT_MSIENABLE, input CONFIG_CPL_BOUNDARY_SEL, // Interrupt Request input INTR_MSI_RDY, // High when interrupt is able to be sent output INTR_MSI_REQUEST, // High to request interrupt, when both INTR_MSI_RDY and INTR_MSI_RE input [C_NUM_CHNL-1:0] CHNL_RX_CLK, output [C_NUM_CHNL-1:0] CHNL_RX, input [C_NUM_CHNL-1:0] CHNL_RX_ACK, output [C_NUM_CHNL-1:0] CHNL_RX_LAST, output [(C_NUM_CHNL*32)-1:0] CHNL_RX_LEN, output [(C_NUM_CHNL*31)-1:0] CHNL_RX_OFF, output [(C_NUM_CHNL*C_PCI_DATA_WIDTH)-1:0] CHNL_RX_DATA, output [C_NUM_CHNL-1:0] CHNL_RX_DATA_VALID, input [C_NUM_CHNL-1:0] CHNL_RX_DATA_REN, input [C_NUM_CHNL-1:0] CHNL_TX_CLK, input [C_NUM_CHNL-1:0] CHNL_TX, output [C_NUM_CHNL-1:0] CHNL_TX_ACK, input [C_NUM_CHNL-1:0] CHNL_TX_LAST, input [(C_NUM_CHNL*32)-1:0] CHNL_TX_LEN, input [(C_NUM_CHNL*31)-1:0] CHNL_TX_OFF, input [(C_NUM_CHNL*C_PCI_DATA_WIDTH)-1:0] CHNL_TX_DATA, input [C_NUM_CHNL-1:0] CHNL_TX_DATA_VALID, output [C_NUM_CHNL-1:0] CHNL_TX_DATA_REN ); localparam C_MAX_READ_REQ = clog2s(C_MAX_READ_REQ_BYTES)-7; // Max read: 000=128B; 001=256B; 010=512B; 011=1024B; 100=2048B; 101=4096B localparam C_NUM_CHNL_WIDTH = clog2s(C_NUM_CHNL); localparam C_PCI_DATA_WORD_WIDTH = clog2s((C_PCI_DATA_WIDTH/32)+1); localparam C_NUM_VECTORS = 2; localparam C_VECTOR_WIDTH = 32; // Interface: Reorder Buffer Output wire [(C_NUM_CHNL*C_PCI_DATA_WORD_WIDTH)-1:0] wRxEngMainDataEn; // Start offset and end offset wire [C_PCI_DATA_WIDTH-1:0] wRxEngData; wire [C_NUM_CHNL-1:0] wRxEngMainDone; wire [C_NUM_CHNL-1:0] wRxEngMainErr; // Interface: Reorder Buffer to SG RX engines wire [(C_NUM_CHNL*C_PCI_DATA_WORD_WIDTH)-1:0] wRxEngSgRxDataEn; wire [C_NUM_CHNL-1:0] wRxEngSgRxDone; wire [C_NUM_CHNL-1:0] wRxEngSgRxErr; // Interface: Reorder Buffer to SG TX engines wire [(C_NUM_CHNL*C_PCI_DATA_WORD_WIDTH)-1:0] wRxEngSgTxDataEn; wire [C_NUM_CHNL-1:0] wRxEngSgTxDone; wire [C_NUM_CHNL-1:0] wRxEngSgTxErr; // Interface: Channel TX Write wire [C_NUM_CHNL-1:0] wTxEngWrReq; wire [(C_NUM_CHNL*`SIG_ADDR_W)-1:0] wTxEngWrAddr; wire [(C_NUM_CHNL*`SIG_LEN_W)-1:0] wTxEngWrLen; wire [(C_NUM_CHNL*C_PCI_DATA_WIDTH)-1:0] wTxEngWrData; wire [C_NUM_CHNL-1:0] wTxEngWrDataRen; wire [C_NUM_CHNL-1:0] wTxEngWrAck; wire [C_NUM_CHNL-1:0] wTxEngWrSent; // Interface: Channel TX Read wire [C_NUM_CHNL-1:0] wTxEngRdReq; wire [(C_NUM_CHNL*2)-1:0] wTxEngRdSgChnl; wire [(C_NUM_CHNL*`SIG_ADDR_W)-1:0] wTxEngRdAddr; wire [(C_NUM_CHNL*`SIG_LEN_W)-1:0] wTxEngRdLen; wire [C_NUM_CHNL-1:0] wTxEngRdAck; // Interface: Channel Interrupts wire [C_NUM_CHNL-1:0] wChnlSgRxBufRecvd; wire [C_NUM_CHNL-1:0] wChnlRxDone; wire [C_NUM_CHNL-1:0] wChnlTxRequest; wire [C_NUM_CHNL-1:0] wChnlTxDone; wire [C_NUM_CHNL-1:0] wChnlSgTxBufRecvd; wire wInternalTagValid; wire [5:0] wInternalTag; wire wExternalTagValid; wire [C_TAG_WIDTH-1:0] wExternalTag; // Interface: Channel - PIO Read wire [C_NUM_CHNL-1:0] wChnlTxLenReady; wire [(`SIG_TXRLEN_W*C_NUM_CHNL)-1:0] wChnlTxReqLen; wire [C_NUM_CHNL-1:0] wChnlTxOfflastReady; wire [(`SIG_OFFLAST_W*C_NUM_CHNL)-1:0] wChnlTxOfflast; wire wCoreSettingsReady; wire [`SIG_CORESETTINGS_W-1:0] wCoreSettings; wire [C_NUM_VECTORS-1:0] wIntrVectorReady; wire [C_NUM_VECTORS*C_VECTOR_WIDTH-1:0] wIntrVector; wire [C_NUM_CHNL-1:0] wChnlTxDoneReady; wire [(`SIG_TXDONELEN_W*C_NUM_CHNL)-1:0] wChnlTxDoneLen; wire [C_NUM_CHNL-1:0] wChnlRxDoneReady; wire [(`SIG_RXDONELEN_W*C_NUM_CHNL)-1:0] wChnlRxDoneLen; wire wChnlNameReady; // Interface: Channel - PIO Write wire [31:0] wChnlReqData; wire [C_NUM_CHNL-1:0] wChnlSgRxLenValid; wire [C_NUM_CHNL-1:0] wChnlSgRxAddrLoValid; wire [C_NUM_CHNL-1:0] wChnlSgRxAddrHiValid; wire [C_NUM_CHNL-1:0] wChnlSgTxLenValid; wire [C_NUM_CHNL-1:0] wChnlSgTxAddrLoValid; wire [C_NUM_CHNL-1:0] wChnlSgTxAddrHiValid; wire [C_NUM_CHNL-1:0] wChnlRxLenValid; wire [C_NUM_CHNL-1:0] wChnlRxOfflastValid; // Interface: TXC Engine wire [C_PCI_DATA_WIDTH-1:0] _wTxcData, wTxcData; wire _wTxcDataValid, wTxcDataValid; wire _wTxcDataStartFlag, wTxcDataStartFlag; wire [clog2s(C_PCI_DATA_WIDTH/32)-1:0] _wTxcDataStartOffset, wTxcDataStartOffset; wire _wTxcDataEndFlag, wTxcDataEndFlag; wire [clog2s(C_PCI_DATA_WIDTH/32)-1:0] _wTxcDataEndOffset, wTxcDataEndOffset; wire _wTxcDataReady, wTxcDataReady; wire _wTxcMetaValid, wTxcMetaValid; wire [`SIG_FBE_W-1:0] _wTxcMetaFdwbe, wTxcMetaFdwbe; wire [`SIG_LBE_W-1:0] _wTxcMetaLdwbe, wTxcMetaLdwbe; wire [`SIG_LOWADDR_W-1:0] _wTxcMetaAddr, wTxcMetaAddr; wire [`SIG_TYPE_W-1:0] _wTxcMetaType, wTxcMetaType; wire [`SIG_LEN_W-1:0] _wTxcMetaLength, wTxcMetaLength; wire [`SIG_BYTECNT_W-1:0] _wTxcMetaByteCount, wTxcMetaByteCount; wire [`SIG_TAG_W-1:0] _wTxcMetaTag, wTxcMetaTag; wire [`SIG_REQID_W-1:0] _wTxcMetaRequesterId, wTxcMetaRequesterId; wire [`SIG_TC_W-1:0] _wTxcMetaTc, wTxcMetaTc; wire [`SIG_ATTR_W-1:0] _wTxcMetaAttr, wTxcMetaAttr; wire _wTxcMetaEp, wTxcMetaEp; wire _wTxcMetaReady, wTxcMetaReady; wire wRxBufSpaceAvail; wire wTxEngRdReqSent; wire wRxEngRdComplete; wire [31:0] wCPciDataWidth; reg [31:0] wCFpgaId; reg [4:0] rWideRst; reg rRst; genvar i; assign wRxEngRdComplete = RXC_DATA_END_FLAG & RXC_DATA_VALID & (RXC_META_LENGTH >= RXC_META_BYTES_REMAINING[`SIG_BYTECNT_W-1:2]);// TODO: Retime (if possible) assign wCoreSettings = {1'd0, wCFpgaId, wCPciDataWidth[8:5], CONFIG_MAX_PAYLOAD_SIZE, CONFIG_MAX_READ_REQUEST_SIZE, CONFIG_LINK_RATE[1:0], CONFIG_LINK_WIDTH, CONFIG_BUS_MASTER_ENABLE, C_NUM_CHNL[3:0]}; // Interface: TXC Engine assign TXC_DATA = wTxcData; assign TXC_DATA_START_FLAG = wTxcDataStartFlag; assign TXC_DATA_START_OFFSET = wTxcDataStartOffset; assign TXC_DATA_END_FLAG = wTxcDataEndFlag; assign TXC_DATA_END_OFFSET = wTxcDataEndOffset; assign TXC_DATA_VALID = wTxcDataValid & ~wPendingRst & DONE_TXC_RST; assign wTxcDataReady = TXC_DATA_READY & ~wPendingRst & DONE_TXC_RST; assign TXC_META_FDWBE = wTxcMetaFdwbe; assign TXC_META_LDWBE = wTxcMetaLdwbe; assign TXC_META_ADDR = wTxcMetaAddr; assign TXC_META_TYPE = wTxcMetaType; assign TXC_META_LENGTH = wTxcMetaLength; assign TXC_META_BYTE_COUNT = wTxcMetaByteCount; assign TXC_META_TAG = wTxcMetaTag; assign TXC_META_REQUESTER_ID = wTxcMetaRequesterId; assign TXC_META_TC = wTxcMetaTc; assign TXC_META_ATTR = wTxcMetaAttr; assign TXC_META_EP = wTxcMetaEp; assign TXC_META_VALID = wTxcMetaValid & ~wPendingRst & DONE_TXC_RST; assign wTxcMetaReady = TXC_META_READY & ~wPendingRst & DONE_TXC_RST; /* Workaround for a bug reported by the NetFPGA group, where the parameter C_PCI_DATA_WIDTH cannot be directly assigned to a wire. */ generate if(C_PCI_DATA_WIDTH == 32) begin assign wCPciDataWidth = 32; end else if (C_PCI_DATA_WIDTH == 64) begin assign wCPciDataWidth = 64; end else if (C_PCI_DATA_WIDTH == 128) begin assign wCPciDataWidth = 128; end else if (C_PCI_DATA_WIDTH == 256) begin assign wCPciDataWidth = 256; end always @(*) begin wCFpgaId = 0; if((C_FPGA_ID & 128) != 0) begin wCFpgaId[7] = 1; end else if ((C_FPGA_ID & 64) != 1) begin wCFpgaId[6] = 1; end else if ((C_FPGA_ID & 32) != 1) begin wCFpgaId[5] = 1; end else if ((C_FPGA_ID & 16) != 1) begin wCFpgaId[4] = 1; end else if ((C_FPGA_ID & 8) != 1) begin wCFpgaId[3] = 1; end else if ((C_FPGA_ID & 4) != 1) begin wCFpgaId[2] = 1; end else if ((C_FPGA_ID & 2) != 1) begin wCFpgaId[1] = 1; end else if ((C_FPGA_ID & 1) != 1) begin wCFpgaId[0] = 1; end end endgenerate /* The purpose of these two hold modules is to safely reset the TX path and still respond to the core status request (which causes a RIFFA reset). We could wait until after the completion has been transmitted, but we have no guarantee that the TX path is operating correctly until after we reset */ pipeline #(// Parameters .C_DEPTH (1), .C_WIDTH (2 * `SIG_FBE_W + `SIG_LOWADDR_W + `SIG_TYPE_W + `SIG_LEN_W + `SIG_BYTECNT_W + `SIG_TAG_W + `SIG_REQID_W + `SIG_TC_W + `SIG_ATTR_W + 1), .C_USE_MEMORY (0) /*AUTOINSTPARAM*/) txc_meta_hold (// Outputs .WR_DATA_READY (_wTxcMetaReady), // NC .RD_DATA ({wTxcMetaFdwbe, wTxcMetaLdwbe, wTxcMetaAddr, wTxcMetaType, wTxcMetaLength, wTxcMetaByteCount, wTxcMetaTag, wTxcMetaRequesterId, wTxcMetaTc, wTxcMetaAttr, wTxcMetaEp}), .RD_DATA_VALID (wTxcMetaValid), // Inputs .WR_DATA ({_wTxcMetaFdwbe, _wTxcMetaLdwbe, _wTxcMetaAddr, _wTxcMetaType, _wTxcMetaLength, _wTxcMetaByteCount, _wTxcMetaTag, _wTxcMetaRequesterId, _wTxcMetaTc, _wTxcMetaAttr, _wTxcMetaEp}), .WR_DATA_VALID (_wTxcMetaValid), .RD_DATA_READY (wTxcMetaReady), .RST_IN (RST_BUS), /*AUTOINST*/ // Inputs .CLK (CLK)); pipeline #(// Parameters .C_DEPTH (1), .C_WIDTH (C_PCI_DATA_WIDTH + 2 * (clog2s(C_PCI_DATA_WIDTH/32) + 1)), .C_USE_MEMORY (0) /*AUTOINSTPARAM*/) txc_data_hold (// Outputs .WR_DATA_READY (_wTxcDataReady), // NC .RD_DATA ({wTxcData, wTxcDataStartFlag, wTxcDataStartOffset, wTxcDataEndFlag, wTxcDataEndOffset}), .RD_DATA_VALID (wTxcDataValid), // Inputs .WR_DATA ({_wTxcData, _wTxcDataStartFlag, _wTxcDataStartOffset, _wTxcDataEndFlag, _wTxcDataEndOffset}), .WR_DATA_VALID (_wTxcDataValid), .RD_DATA_READY (wTxcDataReady), .RST_IN (RST_BUS), /*AUTOINST*/ // Inputs .CLK (CLK)); reset_extender #(.C_RST_COUNT (8) /*AUTOINSTPARAM*/) reset_extender_inst (// Outputs .PENDING_RST (wPendingRst), // Inputs .RST_LOGIC (wCoreSettingsReady), /*AUTOINST*/ // Outputs .RST_OUT (RST_OUT), // Inputs .CLK (CLK), .RST_BUS (RST_BUS)); reorder_queue #(.C_PCI_DATA_WIDTH(C_PCI_DATA_WIDTH), .C_NUM_CHNL(C_NUM_CHNL), .C_MAX_READ_REQ_BYTES(C_MAX_READ_REQ_BYTES), .C_TAG_WIDTH(C_TAG_WIDTH)) reorderQueue (.RST (RST_OUT), .VALID (RXC_DATA_VALID), .DATA_START_FLAG (RXC_DATA_START_FLAG), .DATA_START_OFFSET (RXC_DATA_START_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .DATA_END_FLAG (RXC_DATA_END_FLAG), .DATA_END_OFFSET (RXC_DATA_END_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .DATA (RXC_DATA), .DATA_EN (RXC_DATA_WORD_ENABLE), .DONE (wRxEngRdComplete), .ERR (RXC_META_EP), .TAG (RXC_META_TAG[C_TAG_WIDTH-1:0]), .INT_TAG (wInternalTag), .INT_TAG_VALID (wInternalTagValid), .EXT_TAG (wExternalTag), .EXT_TAG_VALID (wExternalTagValid), .ENG_DATA (wRxEngData), .MAIN_DATA_EN (wRxEngMainDataEn), .MAIN_DONE (wRxEngMainDone), .MAIN_ERR (wRxEngMainErr), .SG_RX_DATA_EN (wRxEngSgRxDataEn), .SG_RX_DONE (wRxEngSgRxDone), .SG_RX_ERR (wRxEngSgRxErr), .SG_TX_DATA_EN (wRxEngSgTxDataEn), .SG_TX_DONE (wRxEngSgTxDone), .SG_TX_ERR (wRxEngSgTxErr), /*AUTOINST*/ // Inputs .CLK (CLK)); registers #(// Parameters .C_PIPELINE_OUTPUT (1), .C_PIPELINE_INPUT (1), /*AUTOINSTPARAM*/ // Parameters .C_PCI_DATA_WIDTH (C_PCI_DATA_WIDTH), .C_NUM_CHNL (C_NUM_CHNL), .C_MAX_READ_REQ_BYTES (C_MAX_READ_REQ_BYTES), .C_VENDOR (C_VENDOR), .C_NUM_VECTORS (C_NUM_VECTORS), .C_VECTOR_WIDTH (C_VECTOR_WIDTH), .C_FPGA_NAME (C_FPGA_NAME)) reg_inst (// Outputs // Write Interfaces .CHNL_REQ_DATA (wChnlReqData[31:0]), .CHNL_SGRX_LEN_VALID (wChnlSgRxLenValid), .CHNL_SGRX_ADDRLO_VALID (wChnlSgRxAddrLoValid), .CHNL_SGRX_ADDRHI_VALID (wChnlSgRxAddrHiValid), .CHNL_SGTX_LEN_VALID (wChnlSgTxLenValid), .CHNL_SGTX_ADDRLO_VALID (wChnlSgTxAddrLoValid), .CHNL_SGTX_ADDRHI_VALID (wChnlSgTxAddrHiValid), .CHNL_RX_LEN_VALID (wChnlRxLenValid), .CHNL_RX_OFFLAST_VALID (wChnlRxOfflastValid), // Read Interfaces .CHNL_TX_LEN_READY (wChnlTxLenReady), .CHNL_TX_OFFLAST_READY (wChnlTxOfflastReady), .CORE_SETTINGS_READY (wCoreSettingsReady), .INTR_VECTOR_READY (wIntrVectorReady), .CHNL_TX_DONE_READY (wChnlTxDoneReady), .CHNL_RX_DONE_READY (wChnlRxDoneReady), .CHNL_NAME_READY (wChnlNameReady), // TODO: Could do this on a per-channel basis // TXC Engine Interface .TXC_DATA_VALID (_wTxcDataValid), .TXC_DATA (_wTxcData[C_PCI_DATA_WIDTH-1:0]), .TXC_DATA_START_FLAG (_wTxcDataStartFlag), .TXC_DATA_START_OFFSET (_wTxcDataStartOffset[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .TXC_DATA_END_FLAG (_wTxcDataEndFlag), .TXC_DATA_END_OFFSET (_wTxcDataEndOffset[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .TXC_META_VALID (_wTxcMetaValid), .TXC_META_FDWBE (_wTxcMetaFdwbe[`SIG_FBE_W-1:0]), .TXC_META_LDWBE (_wTxcMetaLdwbe[`SIG_LBE_W-1:0]), .TXC_META_ADDR (_wTxcMetaAddr[`SIG_LOWADDR_W-1:0]), .TXC_META_TYPE (_wTxcMetaType[`SIG_TYPE_W-1:0]), .TXC_META_LENGTH (_wTxcMetaLength[`SIG_LEN_W-1:0]), .TXC_META_BYTE_COUNT (_wTxcMetaByteCount[`SIG_BYTECNT_W-1:0]), .TXC_META_TAG (_wTxcMetaTag[`SIG_TAG_W-1:0]), .TXC_META_REQUESTER_ID (_wTxcMetaRequesterId[`SIG_REQID_W-1:0]), .TXC_META_TC (_wTxcMetaTc[`SIG_TC_W-1:0]), .TXC_META_ATTR (_wTxcMetaAttr[`SIG_ATTR_W-1:0]), .TXC_META_EP (_wTxcMetaEp), // Inputs // Read Data .CORE_SETTINGS (wCoreSettings), .CHNL_TX_REQLEN (wChnlTxReqLen), .CHNL_TX_OFFLAST (wChnlTxOfflast), .CHNL_TX_DONELEN (wChnlTxDoneLen), .CHNL_RX_DONELEN (wChnlRxDoneLen), .INTR_VECTOR (wIntrVector), .RST_IN (RST_OUT), .TXC_DATA_READY (_wTxcDataReady), .TXC_META_READY (_wTxcMetaReady), /*AUTOINST*/ // Inputs .CLK (CLK), .RXR_DATA (RXR_DATA[C_PCI_DATA_WIDTH-1:0]), .RXR_DATA_VALID (RXR_DATA_VALID), .RXR_DATA_START_FLAG (RXR_DATA_START_FLAG), .RXR_DATA_START_OFFSET (RXR_DATA_START_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .RXR_META_FDWBE (RXR_META_FDWBE[`SIG_FBE_W-1:0]), .RXR_DATA_END_FLAG (RXR_DATA_END_FLAG), .RXR_DATA_END_OFFSET (RXR_DATA_END_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .RXR_META_LDWBE (RXR_META_LDWBE[`SIG_LBE_W-1:0]), .RXR_META_TC (RXR_META_TC[`SIG_TC_W-1:0]), .RXR_META_ATTR (RXR_META_ATTR[`SIG_ATTR_W-1:0]), .RXR_META_TAG (RXR_META_TAG[`SIG_TAG_W-1:0]), .RXR_META_TYPE (RXR_META_TYPE[`SIG_TYPE_W-1:0]), .RXR_META_ADDR (RXR_META_ADDR[`SIG_ADDR_W-1:0]), .RXR_META_BAR_DECODED (RXR_META_BAR_DECODED[`SIG_BARDECODE_W-1:0]), .RXR_META_REQUESTER_ID (RXR_META_REQUESTER_ID[`SIG_REQID_W-1:0]), .RXR_META_LENGTH (RXR_META_LENGTH[`SIG_LEN_W-1:0])); // Track receive buffer flow control credits (header & Data) recv_credit_flow_ctrl rc_fc (// Outputs .RXBUF_SPACE_AVAIL (wRxBufSpaceAvail), // Inputs .RX_ENG_RD_DONE (wRxEngRdComplete), .TX_ENG_RD_REQ_SENT (wTxEngRdReqSent), .RST (RST_OUT), /*AUTOINST*/ // Inputs .CLK (CLK), .CONFIG_MAX_READ_REQUEST_SIZE (CONFIG_MAX_READ_REQUEST_SIZE[2:0]), .CONFIG_MAX_CPL_DATA (CONFIG_MAX_CPL_DATA[11:0]), .CONFIG_MAX_CPL_HDR (CONFIG_MAX_CPL_HDR[7:0]), .CONFIG_CPL_BOUNDARY_SEL (CONFIG_CPL_BOUNDARY_SEL)); // Connect the interrupt vector and controller. interrupt #(.C_NUM_CHNL (C_NUM_CHNL)) intr (// Inputs .RST (RST_OUT), .RX_SG_BUF_RECVD (wChnlSgRxBufRecvd), .RX_TXN_DONE (wChnlRxDone), .TX_TXN (wChnlTxRequest), .TX_SG_BUF_RECVD (wChnlSgTxBufRecvd), .TX_TXN_DONE (wChnlTxDone), .VECT_0_RST (wIntrVectorReady[0]), .VECT_1_RST (wIntrVectorReady[1]), .VECT_RST (_wTxcData[31:0]), .VECT_0 (wIntrVector[31:0]), .VECT_1 (wIntrVector[63:32]), .INTR_LEGACY_CLR (1'd0), /*AUTOINST*/ // Outputs .INTR_MSI_REQUEST (INTR_MSI_REQUEST), // Inputs .CLK (CLK), .CONFIG_INTERRUPT_MSIENABLE (CONFIG_INTERRUPT_MSIENABLE), .INTR_MSI_RDY (INTR_MSI_RDY)); tx_multiplexer #(/*AUTOINSTPARAM*/ // Parameters .C_PCI_DATA_WIDTH (C_PCI_DATA_WIDTH), .C_NUM_CHNL (C_NUM_CHNL), .C_TAG_WIDTH (C_TAG_WIDTH), .C_VENDOR (C_VENDOR), .C_DEPTH_PACKETS (C_DEPTH_PACKETS)) tx_mux_inst ( // Outputs .WR_DATA_REN (wTxEngWrDataRen[C_NUM_CHNL-1:0]), .WR_ACK (wTxEngWrAck[C_NUM_CHNL-1:0]), .RD_ACK (wTxEngRdAck[C_NUM_CHNL-1:0]), .INT_TAG (wInternalTag[5:0]), .INT_TAG_VALID (wInternalTagValid), .TX_ENG_RD_REQ_SENT (wTxEngRdReqSent), // Inputs .RST_IN (RST_OUT), .WR_REQ (wTxEngWrReq[C_NUM_CHNL-1:0]), .WR_ADDR (wTxEngWrAddr[(C_NUM_CHNL*`SIG_ADDR_W)-1:0]), .WR_LEN (wTxEngWrLen[(C_NUM_CHNL*`SIG_LEN_W)-1:0]), .WR_DATA (wTxEngWrData[(C_NUM_CHNL*C_PCI_DATA_WIDTH)-1:0]), .WR_SENT (wTxEngWrSent[C_NUM_CHNL-1:0]), .RD_REQ (wTxEngRdReq[C_NUM_CHNL-1:0]), .RD_SG_CHNL (wTxEngRdSgChnl[(C_NUM_CHNL*2)-1:0]), .RD_ADDR (wTxEngRdAddr[(C_NUM_CHNL*`SIG_ADDR_W)-1:0]), .RD_LEN (wTxEngRdLen[(C_NUM_CHNL*`SIG_LEN_W)-1:0]), .EXT_TAG (wExternalTag[C_TAG_WIDTH-1:0]), .EXT_TAG_VALID (wExternalTagValid), .RXBUF_SPACE_AVAIL (wRxBufSpaceAvail), /*AUTOINST*/ // Outputs .TXR_DATA_VALID (TXR_DATA_VALID), .TXR_DATA (TXR_DATA[C_PCI_DATA_WIDTH-1:0]), .TXR_DATA_START_FLAG (TXR_DATA_START_FLAG), .TXR_DATA_START_OFFSET (TXR_DATA_START_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .TXR_DATA_END_FLAG (TXR_DATA_END_FLAG), .TXR_DATA_END_OFFSET (TXR_DATA_END_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .TXR_META_VALID (TXR_META_VALID), .TXR_META_FDWBE (TXR_META_FDWBE[`SIG_FBE_W-1:0]), .TXR_META_LDWBE (TXR_META_LDWBE[`SIG_LBE_W-1:0]), .TXR_META_ADDR (TXR_META_ADDR[`SIG_ADDR_W-1:0]), .TXR_META_LENGTH (TXR_META_LENGTH[`SIG_LEN_W-1:0]), .TXR_META_TAG (TXR_META_TAG[`SIG_TAG_W-1:0]), .TXR_META_TC (TXR_META_TC[`SIG_TC_W-1:0]), .TXR_META_ATTR (TXR_META_ATTR[`SIG_ATTR_W-1:0]), .TXR_META_TYPE (TXR_META_TYPE[`SIG_TYPE_W-1:0]), .TXR_META_EP (TXR_META_EP), // Inputs .CLK (CLK), .TXR_DATA_READY (TXR_DATA_READY), .TXR_META_READY (TXR_META_READY), .TXR_SENT (TXR_SENT)); // Generate and link up the channels. generate for (i = 0; i < C_NUM_CHNL; i = i + 1) begin : channels channel #( .C_DATA_WIDTH(C_PCI_DATA_WIDTH), .C_MAX_READ_REQ(C_MAX_READ_REQ) ) channel ( .RST(RST_OUT), .CLK(CLK), .CONFIG_MAX_READ_REQUEST_SIZE(CONFIG_MAX_READ_REQUEST_SIZE), .CONFIG_MAX_PAYLOAD_SIZE(CONFIG_MAX_PAYLOAD_SIZE), .PIO_DATA(wChnlReqData), .ENG_DATA(wRxEngData), .SG_RX_BUF_RECVD(wChnlSgRxBufRecvd[i]), .SG_TX_BUF_RECVD(wChnlSgTxBufRecvd[i]), .TXN_TX(wChnlTxRequest[i]), .TXN_TX_DONE(wChnlTxDone[i]), .TXN_RX_DONE(wChnlRxDone[i]), .SG_RX_BUF_LEN_VALID(wChnlSgRxLenValid[i]), .SG_RX_BUF_ADDR_HI_VALID(wChnlSgRxAddrHiValid[i]), .SG_RX_BUF_ADDR_LO_VALID(wChnlSgRxAddrLoValid[i]), .SG_TX_BUF_LEN_VALID(wChnlSgTxLenValid[i]), .SG_TX_BUF_ADDR_HI_VALID(wChnlSgTxAddrHiValid[i]), .SG_TX_BUF_ADDR_LO_VALID(wChnlSgTxAddrLoValid[i]), .TXN_RX_LEN_VALID(wChnlRxLenValid[i]), .TXN_RX_OFF_LAST_VALID(wChnlRxOfflastValid[i]), .TXN_RX_DONE_LEN(wChnlRxDoneLen[(`SIG_RXDONELEN_W*i) +: `SIG_RXDONELEN_W]), .TXN_RX_DONE_ACK(wChnlRxDoneReady[i]), .TXN_TX_ACK(wChnlTxLenReady[i]), // ACK'd on length read .TXN_TX_LEN(wChnlTxReqLen[(`SIG_TXRLEN_W*i) +: `SIG_TXRLEN_W]), .TXN_TX_OFF_LAST(wChnlTxOfflast[(`SIG_OFFLAST_W*i) +: `SIG_OFFLAST_W]), .TXN_TX_DONE_LEN(wChnlTxDoneLen[(`SIG_TXDONELEN_W*i) +:`SIG_TXDONELEN_W]), .TXN_TX_DONE_ACK(wChnlTxDoneReady[i]), .RX_REQ(wTxEngRdReq[i]), .RX_REQ_ACK(wTxEngRdAck[i]), .RX_REQ_TAG(wTxEngRdSgChnl[(2*i) +:2]),// TODO: `SIG_INTERNALTAG_W .RX_REQ_ADDR(wTxEngRdAddr[(`SIG_ADDR_W*i) +:`SIG_ADDR_W]), .RX_REQ_LEN(wTxEngRdLen[(`SIG_LEN_W*i) +:`SIG_LEN_W]), .TX_REQ(wTxEngWrReq[i]), .TX_REQ_ACK(wTxEngWrAck[i]), .TX_ADDR(wTxEngWrAddr[(`SIG_ADDR_W*i) +: `SIG_ADDR_W]), .TX_LEN(wTxEngWrLen[(`SIG_LEN_W*i) +: `SIG_LEN_W]), .TX_DATA(wTxEngWrData[(C_PCI_DATA_WIDTH*i) +:C_PCI_DATA_WIDTH]), .TX_DATA_REN(wTxEngWrDataRen[i]), .TX_SENT(wTxEngWrSent[i]), .MAIN_DATA_EN(wRxEngMainDataEn[(C_PCI_DATA_WORD_WIDTH*i) +:C_PCI_DATA_WORD_WIDTH]), .MAIN_DONE(wRxEngMainDone[i]), .MAIN_ERR(wRxEngMainErr[i]), .SG_RX_DATA_EN(wRxEngSgRxDataEn[(C_PCI_DATA_WORD_WIDTH*i) +:C_PCI_DATA_WORD_WIDTH]), .SG_RX_DONE(wRxEngSgRxDone[i]), .SG_RX_ERR(wRxEngSgRxErr[i]), .SG_TX_DATA_EN(wRxEngSgTxDataEn[(C_PCI_DATA_WORD_WIDTH*i) +:C_PCI_DATA_WORD_WIDTH]), .SG_TX_DONE(wRxEngSgTxDone[i]), .SG_TX_ERR(wRxEngSgTxErr[i]), .CHNL_RX_CLK(CHNL_RX_CLK[i]), .CHNL_RX(CHNL_RX[i]), .CHNL_RX_ACK(CHNL_RX_ACK[i]), .CHNL_RX_LAST(CHNL_RX_LAST[i]), .CHNL_RX_LEN(CHNL_RX_LEN[(32*i) +:32]), .CHNL_RX_OFF(CHNL_RX_OFF[(31*i) +:31]), .CHNL_RX_DATA(CHNL_RX_DATA[(C_PCI_DATA_WIDTH*i) +:C_PCI_DATA_WIDTH]), .CHNL_RX_DATA_VALID(CHNL_RX_DATA_VALID[i]), .CHNL_RX_DATA_REN(CHNL_RX_DATA_REN[i]), .CHNL_TX_CLK(CHNL_TX_CLK[i]), .CHNL_TX(CHNL_TX[i]), .CHNL_TX_ACK(CHNL_TX_ACK[i]), .CHNL_TX_LAST(CHNL_TX_LAST[i]), .CHNL_TX_LEN(CHNL_TX_LEN[(32*i) +:32]), .CHNL_TX_OFF(CHNL_TX_OFF[(31*i) +:31]), .CHNL_TX_DATA(CHNL_TX_DATA[(C_PCI_DATA_WIDTH*i) +:C_PCI_DATA_WIDTH]), .CHNL_TX_DATA_VALID(CHNL_TX_DATA_VALID[i]), .CHNL_TX_DATA_REN(CHNL_TX_DATA_REN[i]) ); end endgenerate endmodule // Local Variables: // verilog-library-directories:("." "registers/" "import") // End:
// (C) 2001-2013 Altera Corporation. All rights reserved. // 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. // $Id: //acds/rel/12.1sp1/ip/merlin/altera_reset_controller/altera_reset_controller.v#1 $ // $Revision: #1 $ // $Date: 2012/10/10 $ // $Author: swbranch $ // -------------------------------------- // Reset controller // // Combines all the input resets and synchronizes // the result to the clk. // -------------------------------------- `timescale 1 ns / 1 ns module altera_reset_controller #( parameter NUM_RESET_INPUTS = 6, parameter OUTPUT_RESET_SYNC_EDGES = "deassert", parameter SYNC_DEPTH = 2 ) ( // -------------------------------------- // We support up to 16 reset inputs, for now // -------------------------------------- input reset_in0, input reset_in1, input reset_in2, input reset_in3, input reset_in4, input reset_in5, input reset_in6, input reset_in7, input reset_in8, input reset_in9, input reset_in10, input reset_in11, input reset_in12, input reset_in13, input reset_in14, input reset_in15, input clk, output reset_out ); localparam ASYNC_RESET = (OUTPUT_RESET_SYNC_EDGES == "deassert"); wire merged_reset; // -------------------------------------- // "Or" all the input resets together // -------------------------------------- assign merged_reset = ( reset_in0 | reset_in1 | reset_in2 | reset_in3 | reset_in4 | reset_in5 | reset_in6 | reset_in7 | reset_in8 | reset_in9 | reset_in10 | reset_in11 | reset_in12 | reset_in13 | reset_in14 | reset_in15 ); // -------------------------------------- // And if required, synchronize it to the required clock domain, // with the correct synchronization type // -------------------------------------- generate if (OUTPUT_RESET_SYNC_EDGES == "none") begin assign reset_out = merged_reset; end else begin altera_reset_synchronizer #( .DEPTH (SYNC_DEPTH), .ASYNC_RESET(ASYNC_RESET) ) alt_rst_sync_uq1 ( .clk (clk), .reset_in (merged_reset), .reset_out (reset_out) ); end endgenerate endmodule
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * 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. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // 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 REGENTS OF THE // UNIVERSITY OF CALIFORNIA 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. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: fifo.v // Version: 1.00 // Verilog Standard: Verilog-2001 // Description: Standard 0-delay fifo implementation. Takes WR_DATA on WR_READY // and WR_VALID. RD_DATA is read on RD_READY and RD_VALID // Author: Dustin Richmond (@darichmond) //----------------------------------------------------------------------------- `timescale 1ns/1ns `include "functions.vh" module fifo #( parameter C_WIDTH = 32, // Data bus width parameter C_DEPTH = 1024, // Depth of the FIFO parameter C_DELAY = 2 ) ( input CLK, // Clock input RST, // Sync reset, active high input [C_WIDTH-1:0] WR_DATA, // Write data input input WR_VALID, // Write enable, high active output WR_READY, // ~Full condition output [C_WIDTH-1:0] RD_DATA, // Read data output input RD_READY, // Read enable, high active output RD_VALID // ~Empty condition ); // Local parameters localparam C_POW2_DEPTH = 2**clog2(C_DEPTH); localparam C_DEPTH_WIDTH = clog2s(C_POW2_DEPTH); wire [C_DELAY:0] wDelayTaps; wire wDelayWrEn; wire wWrEn; wire wRdEn; wire wRdRdy; wire wRdEnInternal; wire wRdEnExternal; wire wEmptyNow; wire wEmptyNext; wire wOutputEmpty; wire wFullNow; wire wFullNext; reg rValid; reg [C_DEPTH_WIDTH:0] rWrPtr,_rWrPtr; reg [C_DEPTH_WIDTH:0] rWrPtrPlus1, _rWrPtrPlus1; reg [C_DEPTH_WIDTH:0] rRdPtr,_rRdPtr; reg [C_DEPTH_WIDTH:0] rRdPtrPlus1,_rRdPtrPlus1; reg rFull,_rFull; reg rEmpty,_rEmpty; assign wRdEnInternal = ~wEmptyNow & ~rValid; // Read enable to propogate data to the BRAM output assign wRdEnExternal = RD_READY & !rEmpty; // Read enable to change data on the output assign wRdEn = wRdEnInternal | wRdEnExternal; assign wRdRdy = RD_READY & rValid; // Read Data already on the output bus assign wWrEn = WR_VALID & !rFull; assign wEmptyNow = (rRdPtr == rWrPtr); assign wEmptyNext = (wRdEn & ~wWrEn & (rWrPtr == rRdPtrPlus1)); assign wFullNow = (rRdPtr[C_DEPTH_WIDTH-1:0] == rWrPtr[C_DEPTH_WIDTH-1:0]) & (rWrPtr[C_DEPTH_WIDTH] != rRdPtr[C_DEPTH_WIDTH]); assign wFullNext = wWrEn & ~wRdEn & (rWrPtrPlus1[C_DEPTH_WIDTH-1:0] == rRdPtr[C_DEPTH_WIDTH-1:0]) & (rWrPtrPlus1[C_DEPTH_WIDTH] != rRdPtr[C_DEPTH_WIDTH]); // Calculate empty assign RD_VALID = rValid; always @ (posedge CLK) begin rEmpty <= #1 (RST ? 1'd1 : _rEmpty); end always @ (*) begin _rEmpty = (wEmptyNow & ~wWrEn) | wEmptyNext; end always @(posedge CLK) begin if(RST) begin rValid <= #1 0; end else if(wRdEn | wRdRdy) begin rValid <= #1 ~(wEmptyNow); end end // Write pointer logic. always @ (posedge CLK) begin if (RST) begin rWrPtr <= #1 0; rWrPtrPlus1 <= #1 1; end else begin rWrPtr <= #1 _rWrPtr; rWrPtrPlus1 <= #1 _rWrPtrPlus1; end end always @ (*) begin if (wWrEn) begin _rWrPtr = rWrPtrPlus1; _rWrPtrPlus1 = rWrPtrPlus1 + 1'd1; end else begin _rWrPtr = rWrPtr; _rWrPtrPlus1 = rWrPtrPlus1; end end // Read pointer logic. always @ (posedge CLK) begin if (RST) begin rRdPtr <= #1 0; rRdPtrPlus1 <= #1 1; end else begin rRdPtr <= #1 _rRdPtr; rRdPtrPlus1 <= #1 _rRdPtrPlus1; end end always @ (*) begin if (wRdEn) begin _rRdPtr = rRdPtrPlus1; _rRdPtrPlus1 = rRdPtrPlus1 + 1'd1; end else begin _rRdPtr = rRdPtr; _rRdPtrPlus1 = rRdPtrPlus1; end end // Calculate full assign WR_READY = ~rFull; always @ (posedge CLK) begin rFull <= #1 (RST ? 1'd0 : _rFull); end always @ (*) begin _rFull = wFullNow | wFullNext; end // Memory block (synthesis attributes applied to this module will // determine the memory option). scsdpram #( .C_WIDTH(C_WIDTH), .C_DEPTH(C_POW2_DEPTH) /*AUTOINSTPARAM*/) mem ( .WR1_EN (wWrEn), .WR1_ADDR (rWrPtr[C_DEPTH_WIDTH-1:0]), .WR1_DATA (WR_DATA), .RD1_EN (wRdEn), .RD1_ADDR (rRdPtr[C_DEPTH_WIDTH-1:0]), .RD1_DATA (RD_DATA), /*AUTOINST*/ // Inputs .CLK (CLK)); shiftreg #( // Parameters .C_DEPTH (C_DELAY), .C_WIDTH (1'b1), .C_VALUE (0) /*AUTOINSTPARAM*/) shiftreg_wr_delay_inst ( // Outputs .RD_DATA (wDelayTaps), // Inputs .RST_IN (RST), .WR_DATA (wWrEn), /*AUTOINST*/ // Inputs .CLK (CLK)); endmodule
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * 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. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // 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 REGENTS OF THE // UNIVERSITY OF CALIFORNIA 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. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: fifo.v // Version: 1.00 // Verilog Standard: Verilog-2001 // Description: Standard 0-delay fifo implementation. Takes WR_DATA on WR_READY // and WR_VALID. RD_DATA is read on RD_READY and RD_VALID // Author: Dustin Richmond (@darichmond) //----------------------------------------------------------------------------- `timescale 1ns/1ns `include "functions.vh" module fifo #( parameter C_WIDTH = 32, // Data bus width parameter C_DEPTH = 1024, // Depth of the FIFO parameter C_DELAY = 2 ) ( input CLK, // Clock input RST, // Sync reset, active high input [C_WIDTH-1:0] WR_DATA, // Write data input input WR_VALID, // Write enable, high active output WR_READY, // ~Full condition output [C_WIDTH-1:0] RD_DATA, // Read data output input RD_READY, // Read enable, high active output RD_VALID // ~Empty condition ); // Local parameters localparam C_POW2_DEPTH = 2**clog2(C_DEPTH); localparam C_DEPTH_WIDTH = clog2s(C_POW2_DEPTH); wire [C_DELAY:0] wDelayTaps; wire wDelayWrEn; wire wWrEn; wire wRdEn; wire wRdRdy; wire wRdEnInternal; wire wRdEnExternal; wire wEmptyNow; wire wEmptyNext; wire wOutputEmpty; wire wFullNow; wire wFullNext; reg rValid; reg [C_DEPTH_WIDTH:0] rWrPtr,_rWrPtr; reg [C_DEPTH_WIDTH:0] rWrPtrPlus1, _rWrPtrPlus1; reg [C_DEPTH_WIDTH:0] rRdPtr,_rRdPtr; reg [C_DEPTH_WIDTH:0] rRdPtrPlus1,_rRdPtrPlus1; reg rFull,_rFull; reg rEmpty,_rEmpty; assign wRdEnInternal = ~wEmptyNow & ~rValid; // Read enable to propogate data to the BRAM output assign wRdEnExternal = RD_READY & !rEmpty; // Read enable to change data on the output assign wRdEn = wRdEnInternal | wRdEnExternal; assign wRdRdy = RD_READY & rValid; // Read Data already on the output bus assign wWrEn = WR_VALID & !rFull; assign wEmptyNow = (rRdPtr == rWrPtr); assign wEmptyNext = (wRdEn & ~wWrEn & (rWrPtr == rRdPtrPlus1)); assign wFullNow = (rRdPtr[C_DEPTH_WIDTH-1:0] == rWrPtr[C_DEPTH_WIDTH-1:0]) & (rWrPtr[C_DEPTH_WIDTH] != rRdPtr[C_DEPTH_WIDTH]); assign wFullNext = wWrEn & ~wRdEn & (rWrPtrPlus1[C_DEPTH_WIDTH-1:0] == rRdPtr[C_DEPTH_WIDTH-1:0]) & (rWrPtrPlus1[C_DEPTH_WIDTH] != rRdPtr[C_DEPTH_WIDTH]); // Calculate empty assign RD_VALID = rValid; always @ (posedge CLK) begin rEmpty <= #1 (RST ? 1'd1 : _rEmpty); end always @ (*) begin _rEmpty = (wEmptyNow & ~wWrEn) | wEmptyNext; end always @(posedge CLK) begin if(RST) begin rValid <= #1 0; end else if(wRdEn | wRdRdy) begin rValid <= #1 ~(wEmptyNow); end end // Write pointer logic. always @ (posedge CLK) begin if (RST) begin rWrPtr <= #1 0; rWrPtrPlus1 <= #1 1; end else begin rWrPtr <= #1 _rWrPtr; rWrPtrPlus1 <= #1 _rWrPtrPlus1; end end always @ (*) begin if (wWrEn) begin _rWrPtr = rWrPtrPlus1; _rWrPtrPlus1 = rWrPtrPlus1 + 1'd1; end else begin _rWrPtr = rWrPtr; _rWrPtrPlus1 = rWrPtrPlus1; end end // Read pointer logic. always @ (posedge CLK) begin if (RST) begin rRdPtr <= #1 0; rRdPtrPlus1 <= #1 1; end else begin rRdPtr <= #1 _rRdPtr; rRdPtrPlus1 <= #1 _rRdPtrPlus1; end end always @ (*) begin if (wRdEn) begin _rRdPtr = rRdPtrPlus1; _rRdPtrPlus1 = rRdPtrPlus1 + 1'd1; end else begin _rRdPtr = rRdPtr; _rRdPtrPlus1 = rRdPtrPlus1; end end // Calculate full assign WR_READY = ~rFull; always @ (posedge CLK) begin rFull <= #1 (RST ? 1'd0 : _rFull); end always @ (*) begin _rFull = wFullNow | wFullNext; end // Memory block (synthesis attributes applied to this module will // determine the memory option). scsdpram #( .C_WIDTH(C_WIDTH), .C_DEPTH(C_POW2_DEPTH) /*AUTOINSTPARAM*/) mem ( .WR1_EN (wWrEn), .WR1_ADDR (rWrPtr[C_DEPTH_WIDTH-1:0]), .WR1_DATA (WR_DATA), .RD1_EN (wRdEn), .RD1_ADDR (rRdPtr[C_DEPTH_WIDTH-1:0]), .RD1_DATA (RD_DATA), /*AUTOINST*/ // Inputs .CLK (CLK)); shiftreg #( // Parameters .C_DEPTH (C_DELAY), .C_WIDTH (1'b1), .C_VALUE (0) /*AUTOINSTPARAM*/) shiftreg_wr_delay_inst ( // Outputs .RD_DATA (wDelayTaps), // Inputs .RST_IN (RST), .WR_DATA (wWrEn), /*AUTOINST*/ // Inputs .CLK (CLK)); endmodule
/* :Project FPGA-Imaging-Library :Design FrameController2 :Function Controlling a frame(block ram etc.), writing or reading with counts. For controlling a BlockRAM from xilinx. Give the first output after mul_delay + 2 + ram_read_latency cycles while the input enable. :Module Main module :Version 1.0 :Modified 2015-05-25 Copyright (C) 2015 Tianyu Dai (dtysky) <[email protected]> This library 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 library 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 library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Homepage for this project: http://fil.dtysky.moe Sources for this project: https://github.com/dtysky/FPGA-Imaging-Library My e-mail: [email protected] My blog: http://dtysky.moe */ `timescale 1ns / 1ps module FrameController2( clk, rst_n, in_count_x, in_count_y, in_enable, in_data, out_ready, out_data, ram_addr); /* ::description This module's working mode. ::range 0 for Pipline, 1 for Req-ack */ parameter work_mode = 0; /* ::description This module's WR mode. ::range 0 for Write, 1 for Read */ parameter wr_mode = 0; /* ::description Data bit width. */ parameter data_width = 8; /* ::description Width of image. ::range 1 - 4096 */ parameter im_width = 320; /* ::description Height of image. ::range 1 - 4096 */ parameter im_height = 240; /* ::description The bits of width of image. ::range Depend on width of image */ parameter im_width_bits = 9; /* ::description Address bit width of a ram for storing this image. ::range Depend on im_width and im_height. */ parameter addr_width = 17; /* ::description RL of RAM, in xilinx 7-series device, it is 2. ::range 0 - 15, Depend on your using ram. */ parameter ram_read_latency = 2; /* ::description Delay for multiplier. ::range Depend on your multilpliers' configurations */ parameter mul_delay = 3; /* ::description Clock. */ input clk; /* ::description Reset, active low. */ input rst_n; /* ::description Input pixel count for width. */ input[im_width_bits - 1 : 0] in_count_x; /* ::description Input pixel count for height. */ input[im_width_bits - 1 : 0] in_count_y; /* ::description Input data enable, in pipeline mode, it works as another rst_n, in req-ack mode, only it is high will in_data can be really changes. */ input in_enable; /* ::description Input data, it must be synchronous with in_enable. */ input [data_width - 1 : 0] in_data; /* ::description Output data ready, in both two mode, it will be high while the out_data can be read. */ output out_ready; /* ::description Output data, it will be synchronous with out_ready. */ output[data_width - 1 : 0] out_data; /* ::description Address for ram. */ output[addr_width - 1 : 0] ram_addr; reg[3 : 0] con_enable; reg[im_width_bits - 1 : 0] reg_in_count_x; reg[im_width_bits - 1 : 0] reg_in_count_y; reg[addr_width - 1 : 0] reg_addr; wire[11 : 0] mul_a, mul_b; wire[23 : 0] mul_p; assign mul_a = {{(12 - im_width_bits){1'b0}}, in_count_y}; assign mul_b = im_width; genvar i; generate /* ::description Multiplier for Unsigned 12bits x Unsigned 12bits, used for creating address for frame. You can configure the multiplier by yourself, then change the "mul_delay". You can not change the ports' configurations! */ Multiplier12x12FR2 Mul(.CLK(clk), .A(mul_a), .B(mul_b), .SCLR(~rst_n), .P(mul_p)); for (i = 0; i < mul_delay; i = i + 1) begin : conut_buffer reg[im_width_bits - 1 : 0] b; if(i == 0) begin always @(posedge clk) b <= in_count_x; end else begin always @(posedge clk) b <= conut_buffer[i - 1].b; end end always @(posedge clk or negedge rst_n or negedge in_enable) begin if(~rst_n || ~in_enable) begin reg_addr <= 0; end else begin reg_addr <= mul_p + conut_buffer[mul_delay - 1].b; end end assign ram_addr = reg_addr; if(wr_mode == 0) begin always @(posedge clk or negedge rst_n or negedge in_enable) begin if(~rst_n || ~in_enable) con_enable <= 0; else if(con_enable == mul_delay + 1) con_enable <= con_enable; else con_enable <= con_enable + 1; end assign out_ready = con_enable == mul_delay + 1 ? 1 : 0; if(work_mode == 0) begin for (i = 0; i < mul_delay + 1; i = i + 1) begin : buffer reg[data_width - 1 : 0] b; if(i == 0) begin always @(posedge clk) b <= in_data; end else begin always @(posedge clk) b <= buffer[i - 1].b; end end assign out_data = out_ready ? buffer[mul_delay].b : 0; end else begin reg[data_width - 1 : 0] reg_out_data; always @(posedge in_enable) reg_out_data = in_data; assign out_data = out_ready ? reg_out_data : 0; end end else begin always @(posedge clk or negedge rst_n or negedge in_enable) begin if(~rst_n || ~in_enable) con_enable <= 0; else if (con_enable == mul_delay + 1 + ram_read_latency) con_enable <= con_enable; else con_enable <= con_enable + 1; end assign out_data = out_ready ? in_data : 0; assign out_ready = con_enable == mul_delay + 1 + ram_read_latency ? 1 : 0; end endgenerate endmodule
/* :Project FPGA-Imaging-Library :Design FrameController2 :Function Controlling a frame(block ram etc.), writing or reading with counts. For controlling a BlockRAM from xilinx. Give the first output after mul_delay + 2 + ram_read_latency cycles while the input enable. :Module Main module :Version 1.0 :Modified 2015-05-25 Copyright (C) 2015 Tianyu Dai (dtysky) <[email protected]> This library 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 library 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 library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Homepage for this project: http://fil.dtysky.moe Sources for this project: https://github.com/dtysky/FPGA-Imaging-Library My e-mail: [email protected] My blog: http://dtysky.moe */ `timescale 1ns / 1ps module FrameController2( clk, rst_n, in_count_x, in_count_y, in_enable, in_data, out_ready, out_data, ram_addr); /* ::description This module's working mode. ::range 0 for Pipline, 1 for Req-ack */ parameter work_mode = 0; /* ::description This module's WR mode. ::range 0 for Write, 1 for Read */ parameter wr_mode = 0; /* ::description Data bit width. */ parameter data_width = 8; /* ::description Width of image. ::range 1 - 4096 */ parameter im_width = 320; /* ::description Height of image. ::range 1 - 4096 */ parameter im_height = 240; /* ::description The bits of width of image. ::range Depend on width of image */ parameter im_width_bits = 9; /* ::description Address bit width of a ram for storing this image. ::range Depend on im_width and im_height. */ parameter addr_width = 17; /* ::description RL of RAM, in xilinx 7-series device, it is 2. ::range 0 - 15, Depend on your using ram. */ parameter ram_read_latency = 2; /* ::description Delay for multiplier. ::range Depend on your multilpliers' configurations */ parameter mul_delay = 3; /* ::description Clock. */ input clk; /* ::description Reset, active low. */ input rst_n; /* ::description Input pixel count for width. */ input[im_width_bits - 1 : 0] in_count_x; /* ::description Input pixel count for height. */ input[im_width_bits - 1 : 0] in_count_y; /* ::description Input data enable, in pipeline mode, it works as another rst_n, in req-ack mode, only it is high will in_data can be really changes. */ input in_enable; /* ::description Input data, it must be synchronous with in_enable. */ input [data_width - 1 : 0] in_data; /* ::description Output data ready, in both two mode, it will be high while the out_data can be read. */ output out_ready; /* ::description Output data, it will be synchronous with out_ready. */ output[data_width - 1 : 0] out_data; /* ::description Address for ram. */ output[addr_width - 1 : 0] ram_addr; reg[3 : 0] con_enable; reg[im_width_bits - 1 : 0] reg_in_count_x; reg[im_width_bits - 1 : 0] reg_in_count_y; reg[addr_width - 1 : 0] reg_addr; wire[11 : 0] mul_a, mul_b; wire[23 : 0] mul_p; assign mul_a = {{(12 - im_width_bits){1'b0}}, in_count_y}; assign mul_b = im_width; genvar i; generate /* ::description Multiplier for Unsigned 12bits x Unsigned 12bits, used for creating address for frame. You can configure the multiplier by yourself, then change the "mul_delay". You can not change the ports' configurations! */ Multiplier12x12FR2 Mul(.CLK(clk), .A(mul_a), .B(mul_b), .SCLR(~rst_n), .P(mul_p)); for (i = 0; i < mul_delay; i = i + 1) begin : conut_buffer reg[im_width_bits - 1 : 0] b; if(i == 0) begin always @(posedge clk) b <= in_count_x; end else begin always @(posedge clk) b <= conut_buffer[i - 1].b; end end always @(posedge clk or negedge rst_n or negedge in_enable) begin if(~rst_n || ~in_enable) begin reg_addr <= 0; end else begin reg_addr <= mul_p + conut_buffer[mul_delay - 1].b; end end assign ram_addr = reg_addr; if(wr_mode == 0) begin always @(posedge clk or negedge rst_n or negedge in_enable) begin if(~rst_n || ~in_enable) con_enable <= 0; else if(con_enable == mul_delay + 1) con_enable <= con_enable; else con_enable <= con_enable + 1; end assign out_ready = con_enable == mul_delay + 1 ? 1 : 0; if(work_mode == 0) begin for (i = 0; i < mul_delay + 1; i = i + 1) begin : buffer reg[data_width - 1 : 0] b; if(i == 0) begin always @(posedge clk) b <= in_data; end else begin always @(posedge clk) b <= buffer[i - 1].b; end end assign out_data = out_ready ? buffer[mul_delay].b : 0; end else begin reg[data_width - 1 : 0] reg_out_data; always @(posedge in_enable) reg_out_data = in_data; assign out_data = out_ready ? reg_out_data : 0; end end else begin always @(posedge clk or negedge rst_n or negedge in_enable) begin if(~rst_n || ~in_enable) con_enable <= 0; else if (con_enable == mul_delay + 1 + ram_read_latency) con_enable <= con_enable; else con_enable <= con_enable + 1; end assign out_data = out_ready ? in_data : 0; assign out_ready = con_enable == mul_delay + 1 + ram_read_latency ? 1 : 0; end endgenerate endmodule
/* :Project FPGA-Imaging-Library :Design FrameController2 :Function Controlling a frame(block ram etc.), writing or reading with counts. For controlling a BlockRAM from xilinx. Give the first output after mul_delay + 2 + ram_read_latency cycles while the input enable. :Module Main module :Version 1.0 :Modified 2015-05-25 Copyright (C) 2015 Tianyu Dai (dtysky) <[email protected]> This library 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 library 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 library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Homepage for this project: http://fil.dtysky.moe Sources for this project: https://github.com/dtysky/FPGA-Imaging-Library My e-mail: [email protected] My blog: http://dtysky.moe */ `timescale 1ns / 1ps module FrameController2( clk, rst_n, in_count_x, in_count_y, in_enable, in_data, out_ready, out_data, ram_addr); /* ::description This module's working mode. ::range 0 for Pipline, 1 for Req-ack */ parameter work_mode = 0; /* ::description This module's WR mode. ::range 0 for Write, 1 for Read */ parameter wr_mode = 0; /* ::description Data bit width. */ parameter data_width = 8; /* ::description Width of image. ::range 1 - 4096 */ parameter im_width = 320; /* ::description Height of image. ::range 1 - 4096 */ parameter im_height = 240; /* ::description The bits of width of image. ::range Depend on width of image */ parameter im_width_bits = 9; /* ::description Address bit width of a ram for storing this image. ::range Depend on im_width and im_height. */ parameter addr_width = 17; /* ::description RL of RAM, in xilinx 7-series device, it is 2. ::range 0 - 15, Depend on your using ram. */ parameter ram_read_latency = 2; /* ::description Delay for multiplier. ::range Depend on your multilpliers' configurations */ parameter mul_delay = 3; /* ::description Clock. */ input clk; /* ::description Reset, active low. */ input rst_n; /* ::description Input pixel count for width. */ input[im_width_bits - 1 : 0] in_count_x; /* ::description Input pixel count for height. */ input[im_width_bits - 1 : 0] in_count_y; /* ::description Input data enable, in pipeline mode, it works as another rst_n, in req-ack mode, only it is high will in_data can be really changes. */ input in_enable; /* ::description Input data, it must be synchronous with in_enable. */ input [data_width - 1 : 0] in_data; /* ::description Output data ready, in both two mode, it will be high while the out_data can be read. */ output out_ready; /* ::description Output data, it will be synchronous with out_ready. */ output[data_width - 1 : 0] out_data; /* ::description Address for ram. */ output[addr_width - 1 : 0] ram_addr; reg[3 : 0] con_enable; reg[im_width_bits - 1 : 0] reg_in_count_x; reg[im_width_bits - 1 : 0] reg_in_count_y; reg[addr_width - 1 : 0] reg_addr; wire[11 : 0] mul_a, mul_b; wire[23 : 0] mul_p; assign mul_a = {{(12 - im_width_bits){1'b0}}, in_count_y}; assign mul_b = im_width; genvar i; generate /* ::description Multiplier for Unsigned 12bits x Unsigned 12bits, used for creating address for frame. You can configure the multiplier by yourself, then change the "mul_delay". You can not change the ports' configurations! */ Multiplier12x12FR2 Mul(.CLK(clk), .A(mul_a), .B(mul_b), .SCLR(~rst_n), .P(mul_p)); for (i = 0; i < mul_delay; i = i + 1) begin : conut_buffer reg[im_width_bits - 1 : 0] b; if(i == 0) begin always @(posedge clk) b <= in_count_x; end else begin always @(posedge clk) b <= conut_buffer[i - 1].b; end end always @(posedge clk or negedge rst_n or negedge in_enable) begin if(~rst_n || ~in_enable) begin reg_addr <= 0; end else begin reg_addr <= mul_p + conut_buffer[mul_delay - 1].b; end end assign ram_addr = reg_addr; if(wr_mode == 0) begin always @(posedge clk or negedge rst_n or negedge in_enable) begin if(~rst_n || ~in_enable) con_enable <= 0; else if(con_enable == mul_delay + 1) con_enable <= con_enable; else con_enable <= con_enable + 1; end assign out_ready = con_enable == mul_delay + 1 ? 1 : 0; if(work_mode == 0) begin for (i = 0; i < mul_delay + 1; i = i + 1) begin : buffer reg[data_width - 1 : 0] b; if(i == 0) begin always @(posedge clk) b <= in_data; end else begin always @(posedge clk) b <= buffer[i - 1].b; end end assign out_data = out_ready ? buffer[mul_delay].b : 0; end else begin reg[data_width - 1 : 0] reg_out_data; always @(posedge in_enable) reg_out_data = in_data; assign out_data = out_ready ? reg_out_data : 0; end end else begin always @(posedge clk or negedge rst_n or negedge in_enable) begin if(~rst_n || ~in_enable) con_enable <= 0; else if (con_enable == mul_delay + 1 + ram_read_latency) con_enable <= con_enable; else con_enable <= con_enable + 1; end assign out_data = out_ready ? in_data : 0; assign out_ready = con_enable == mul_delay + 1 + ram_read_latency ? 1 : 0; end endgenerate endmodule
////////////////////////////////////////////////////////////////////////////////// // InterChannelELPBuffer.v for Cosmos OpenSSD // Copyright (c) 2015 Hanyang University ENC Lab. // Contributed by Jinwoo Jeong <[email protected]> // Ilyong Jung <[email protected]> // Yong Ho Song <[email protected]> // // This file is part of Cosmos OpenSSD. // // Cosmos OpenSSD 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. // // Cosmos OpenSSD 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 Cosmos OpenSSD; see the file COPYING. // If not, see <http://www.gnu.org/licenses/>. ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// // Company: ENC Lab. <http://enc.hanyang.ac.kr> // Engineer: Jinwoo Jeong <[email protected]> // Ilyong Jung <[email protected]> // // Project Name: Cosmos OpenSSD // Design Name: BCH Page Decoder // Module Name: InterChannelELPBuffer // File Name: InterChannelELPBuffer.v // // Version: v1.0.0 // // Description: Error location polynomial (ELP) coefficient buffer array // ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// // Revision History: // // * v1.0.0 // - first draft ////////////////////////////////////////////////////////////////////////////////// `timescale 1ns / 1ps module InterChannelELPBuffer #( parameter Channel = 4, parameter Multi = 2, parameter MaxErrorCountBits = 9, parameter GaloisFieldDegree = 12, parameter ELPCoefficients = 15 ) ( iClock , iReset , iChannelSel , iKESEnd , iKESFail , iClusterCorrectionEnd , iCorrectedChunkNumber , iChunkErrorCount , oBufferReady , iELPCoefficient000 , iELPCoefficient001 , iELPCoefficient002 , iELPCoefficient003 , iELPCoefficient004 , iELPCoefficient005 , iELPCoefficient006 , iELPCoefficient007 , iELPCoefficient008 , iELPCoefficient009 , iELPCoefficient010 , iELPCoefficient011 , iELPCoefficient012 , iELPCoefficient013 , iELPCoefficient014 , iCSAvailable , oIntraSharedKESEnd , oErroredChunk , oCorrectionFail , oClusterErrorCount , oELPCoefficients ); input iClock ; input iReset ; input [3:0] iChannelSel ; input iKESEnd ; input iKESFail ; input iClusterCorrectionEnd ; input iCorrectedChunkNumber ; input [3:0] iChunkErrorCount ; output oBufferReady ; input [GaloisFieldDegree - 1:0] iELPCoefficient000 ; input [GaloisFieldDegree - 1:0] iELPCoefficient001 ; input [GaloisFieldDegree - 1:0] iELPCoefficient002 ; input [GaloisFieldDegree - 1:0] iELPCoefficient003 ; input [GaloisFieldDegree - 1:0] iELPCoefficient004 ; input [GaloisFieldDegree - 1:0] iELPCoefficient005 ; input [GaloisFieldDegree - 1:0] iELPCoefficient006 ; input [GaloisFieldDegree - 1:0] iELPCoefficient007 ; input [GaloisFieldDegree - 1:0] iELPCoefficient008 ; input [GaloisFieldDegree - 1:0] iELPCoefficient009 ; input [GaloisFieldDegree - 1:0] iELPCoefficient010 ; input [GaloisFieldDegree - 1:0] iELPCoefficient011 ; input [GaloisFieldDegree - 1:0] iELPCoefficient012 ; input [GaloisFieldDegree - 1:0] iELPCoefficient013 ; input [GaloisFieldDegree - 1:0] iELPCoefficient014 ; input [Channel - 1:0] iCSAvailable ; output [Channel - 1:0] oIntraSharedKESEnd ; output [Channel*Multi - 1:0] oErroredChunk ; output [Channel*Multi - 1:0] oCorrectionFail ; output [Channel*Multi*MaxErrorCountBits - 1:0] oClusterErrorCount ; output [Channel*Multi*GaloisFieldDegree*ELPCoefficients - 1:0] oELPCoefficients ; reg rChannelSel ; wire [Channel - 1:0] wKESEnd ; wire [Channel - 1:0] wBufferReady ; assign wKESEnd = (iKESEnd) ? iChannelSel : 0; genvar c; generate for (c = 0; c < Channel; c = c + 1) d_KES_CS_buffer #( .Multi(2), .GaloisFieldDegree(12), .MaxErrorCountBits(9), .ELPCoefficients(15) ) Inst_PageDecoderCSBuffer ( .i_clk (iClock ), .i_RESET (iReset ), .i_stop_dec (1'b0 ), .i_exe_buf (wKESEnd[c] ), .i_kes_fail (iKESFail ), .i_buf_sequence_end (iClusterCorrectionEnd ), .i_chunk_number (iCorrectedChunkNumber ), .i_error_count (iChunkErrorCount ), .i_v_000 (iELPCoefficient000 ), .i_v_001 (iELPCoefficient001 ), .i_v_002 (iELPCoefficient002 ), .i_v_003 (iELPCoefficient003 ), .i_v_004 (iELPCoefficient004 ), .i_v_005 (iELPCoefficient005 ), .i_v_006 (iELPCoefficient006 ), .i_v_007 (iELPCoefficient007 ), .i_v_008 (iELPCoefficient008 ), .i_v_009 (iELPCoefficient009 ), .i_v_010 (iELPCoefficient010 ), .i_v_011 (iELPCoefficient011 ), .i_v_012 (iELPCoefficient012 ), .i_v_013 (iELPCoefficient013 ), .i_v_014 (iELPCoefficient014 ), .i_cs_available (iCSAvailable[c] ), .o_buf_available (wBufferReady[c] ), .o_exe_cs (oIntraSharedKESEnd[c] ), .o_kes_sequence_end (oErroredChunk[(c+1)*Multi - 1: c*Multi] ), .o_kes_fail (oCorrectionFail[(c+1)*Multi - 1: c*Multi] ), .o_error_count (oClusterErrorCount[(c+1)*Multi*MaxErrorCountBits - 1: c*Multi*MaxErrorCountBits] ), .o_ELP_coef (oELPCoefficients[(c+1)*Multi*GaloisFieldDegree*ELPCoefficients - 1: c*Multi*GaloisFieldDegree*ELPCoefficients] ) ); endgenerate assign oBufferReady = (iChannelSel == 4'b0001) ? wBufferReady[0] : (iChannelSel == 4'b0010) ? wBufferReady[1] : (iChannelSel == 4'b0100) ? wBufferReady[2] : (iChannelSel == 4'b1000) ? wBufferReady[3] : 1'b0; endmodule
////////////////////////////////////////////////////////////////////////////////// // d_KES_PE_ELU_NMLodr.v for Cosmos OpenSSD // Copyright (c) 2015 Hanyang University ENC Lab. // Contributed by Jinwoo Jeong <[email protected]> // Ilyong Jung <[email protected]> // Yong Ho Song <[email protected]> // // This file is part of Cosmos OpenSSD. // // Cosmos OpenSSD 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. // // Cosmos OpenSSD 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 Cosmos OpenSSD; see the file COPYING. // If not, see <http://www.gnu.org/licenses/>. ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// // Company: ENC Lab. <http://enc.hanyang.ac.kr> // Engineer: Jinwoo Jeong <[email protected]> // Ilyong Jung <[email protected]> // // Project Name: Cosmos OpenSSD // Design Name: BCH Page Decoder // Module Name: d_KES_PE_ELU_NMLodr // File Name: d_KES_PE_ELU_NMLodr.v // // Version: v1.1.1-256B_T14 // // Description: // - Processing Element: Error Locator Update module, normal order // - for binary version of inversion-less Berlekamp-Massey algorithm (iBM.b) // - for data area ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// // Revision History: // // * v1.1.1 // - minor modification for releasing // // * v1.1.0 // - change state machine: divide states // - insert additional registers // - improve frequency characteristic // // * v1.0.0 // - first draft ////////////////////////////////////////////////////////////////////////////////// `include "d_KES_parameters.vh" `timescale 1ns / 1ps module d_KES_PE_ELU_NMLodr // error locate update module: normal order ( input wire i_clk, input wire i_RESET_KES, input wire i_stop_dec, input wire i_EXECUTE_PE_ELU, input wire [`D_KES_GF_ORDER-1:0] i_v_2i_Xm1, input wire [`D_KES_GF_ORDER-1:0] i_k_2i_Xm1, input wire [`D_KES_GF_ORDER-1:0] i_k_2i_Xm2, input wire [`D_KES_GF_ORDER-1:0] i_d_2i, input wire [`D_KES_GF_ORDER-1:0] i_delta_2im2, input wire i_condition_2i, output reg [`D_KES_GF_ORDER-1:0] o_v_2i_X, output reg o_v_2i_X_deg_chk_bit, output reg [`D_KES_GF_ORDER-1:0] o_k_2i_X ); parameter [11:0] D_KES_VALUE_ZERO = 12'b0000_0000_0000; parameter [11:0] D_KES_VALUE_ONE = 12'b0000_0000_0001; // FSM parameters parameter PE_ELU_RST = 2'b01; // reset parameter PE_ELU_OUT = 2'b10; // output buffer update // variable declaration reg [1:0] r_cur_state; reg [1:0] r_nxt_state; wire [`D_KES_GF_ORDER-1:0] w_v_2ip2_X_term_A; wire [`D_KES_GF_ORDER-1:0] w_v_2ip2_X_term_B; wire [`D_KES_GF_ORDER-1:0] w_v_2ip2_X; wire [`D_KES_GF_ORDER-1:0] w_k_2ip2_X; // update current state to next state always @ (posedge i_clk) begin if ((i_RESET_KES) || (i_stop_dec)) begin r_cur_state <= PE_ELU_RST; end else begin r_cur_state <= r_nxt_state; end end // decide next state always @ ( * ) begin case (r_cur_state) PE_ELU_RST: begin r_nxt_state <= (i_EXECUTE_PE_ELU)? (PE_ELU_OUT):(PE_ELU_RST); end PE_ELU_OUT: begin r_nxt_state <= PE_ELU_RST; end default: begin r_nxt_state <= PE_ELU_RST; end endcase end // state behaviour always @ (posedge i_clk) begin if ((i_RESET_KES) || (i_stop_dec)) begin // initializing o_v_2i_X[`D_KES_GF_ORDER-1:0] <= D_KES_VALUE_ZERO[`D_KES_GF_ORDER-1:0]; o_v_2i_X_deg_chk_bit <= 0; o_k_2i_X[`D_KES_GF_ORDER-1:0] <= D_KES_VALUE_ZERO[`D_KES_GF_ORDER-1:0]; end else begin case (r_nxt_state) PE_ELU_RST: begin // hold original data o_v_2i_X[`D_KES_GF_ORDER-1:0] <= o_v_2i_X[`D_KES_GF_ORDER-1:0]; o_v_2i_X_deg_chk_bit <= o_v_2i_X_deg_chk_bit; o_k_2i_X[`D_KES_GF_ORDER-1:0] <= o_k_2i_X[`D_KES_GF_ORDER-1:0]; end PE_ELU_OUT: begin // output update only o_v_2i_X[`D_KES_GF_ORDER-1:0] <= w_v_2ip2_X[`D_KES_GF_ORDER-1:0]; o_v_2i_X_deg_chk_bit <= |(w_v_2ip2_X[`D_KES_GF_ORDER-1:0]); o_k_2i_X[`D_KES_GF_ORDER-1:0] <= w_k_2ip2_X[`D_KES_GF_ORDER-1:0]; end default: begin o_v_2i_X[`D_KES_GF_ORDER-1:0] <= o_v_2i_X[`D_KES_GF_ORDER-1:0]; o_v_2i_X_deg_chk_bit <= o_v_2i_X_deg_chk_bit; o_k_2i_X[`D_KES_GF_ORDER-1:0] <= o_k_2i_X[`D_KES_GF_ORDER-1:0]; end endcase end end d_parallel_FFM_gate_GF12 d_delta_2im2_FFM_v_2i_X ( .i_poly_form_A (i_delta_2im2[`D_KES_GF_ORDER-1:0]), .i_poly_form_B (o_v_2i_X[`D_KES_GF_ORDER-1:0]), .o_poly_form_result(w_v_2ip2_X_term_A[`D_KES_GF_ORDER-1:0])); d_parallel_FFM_gate_GF12 d_d_2i_FFM_k_2i_Xm1 ( .i_poly_form_A (i_d_2i[`D_KES_GF_ORDER-1:0]), .i_poly_form_B (i_k_2i_Xm1[`D_KES_GF_ORDER-1:0]), .o_poly_form_result(w_v_2ip2_X_term_B[`D_KES_GF_ORDER-1:0])); assign w_v_2ip2_X[`D_KES_GF_ORDER-1:0] = w_v_2ip2_X_term_A[`D_KES_GF_ORDER-1:0] ^ w_v_2ip2_X_term_B[`D_KES_GF_ORDER-1:0]; assign w_k_2ip2_X[`D_KES_GF_ORDER-1:0] = (i_condition_2i)? (i_v_2i_Xm1[`D_KES_GF_ORDER-1:0]):(i_k_2i_Xm2[`D_KES_GF_ORDER-1:0]); endmodule
/**************************************************************************************** * * File Name: ddr3.v * Version: 1.61 * Model: BUS Functional * * Dependencies: ddr3_model_parameters_c3.vh * * Description: Micron SDRAM DDR3 (Double Data Rate 3) * * Limitation: - doesn't check for average refresh timings * - positive ck and ck_n edges are used to form internal clock * - positive dqs and dqs_n edges are used to latch data * - test mode is not modeled * - Duty Cycle Corrector is not modeled * - Temperature Compensated Self Refresh is not modeled * - DLL off mode is not modeled. * * Note: - Set simulator resolution to "ps" accuracy * - Set DEBUG = 0 to disable $display messages * * Disclaimer This software code and all associated documentation, comments or other * of Warranty: information (collectively "Software") is provided "AS IS" without * warranty of any kind. MICRON TECHNOLOGY, INC. ("MTI") EXPRESSLY * DISCLAIMS ALL WARRANTIES EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED * TO, NONINFRINGEMENT OF THIRD PARTY RIGHTS, AND ANY IMPLIED WARRANTIES * OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE. MTI DOES NOT * WARRANT THAT THE SOFTWARE WILL MEET YOUR REQUIREMENTS, OR THAT THE * OPERATION OF THE SOFTWARE WILL BE UNINTERRUPTED OR ERROR-FREE. * FURTHERMORE, MTI DOES NOT MAKE ANY REPRESENTATIONS REGARDING THE USE OR * THE RESULTS OF THE USE OF THE SOFTWARE IN TERMS OF ITS CORRECTNESS, * ACCURACY, RELIABILITY, OR OTHERWISE. THE ENTIRE RISK ARISING OUT OF USE * OR PERFORMANCE OF THE SOFTWARE REMAINS WITH YOU. IN NO EVENT SHALL MTI, * ITS AFFILIATED COMPANIES OR THEIR SUPPLIERS BE LIABLE FOR ANY DIRECT, * INDIRECT, CONSEQUENTIAL, INCIDENTAL, OR SPECIAL DAMAGES (INCLUDING, * WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS, BUSINESS INTERRUPTION, * OR LOSS OF INFORMATION) ARISING OUT OF YOUR USE OF OR INABILITY TO USE * THE SOFTWARE, EVEN IF MTI HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH * DAMAGES. Because some jurisdictions prohibit the exclusion or * limitation of liability for consequential or incidental damages, the * above limitation may not apply to you. * * Copyright 2003 Micron Technology, Inc. All rights reserved. * * Rev Author Date Changes * --------------------------------------------------------------------------------------- * 0.41 JMK 05/12/06 Removed auto-precharge to power down error check. * 0.42 JMK 08/25/06 Created internal clock using ck and ck_n. * TDQS can only be enabled in EMR for x8 configurations. * CAS latency is checked vs frequency when DLL locks. * Improved checking of DQS during writes. * Added true BL4 operation. * 0.43 JMK 08/14/06 Added checking for setting reserved bits in Mode Registers. * Added ODTS Readout. * Replaced tZQCL with tZQinit and tZQoper * Fixed tWRPDEN and tWRAPDEN during BC4MRS and BL4MRS. * Added tRFC checking for Refresh to Power-Down Re-Entry. * Added tXPDLL checking for Power-Down Exit to Refresh to Power-Down Entry * Added Clock Frequency Change during Precharge Power-Down. * Added -125x speed grades. * Fixed tRCD checking during Write. * 1.00 JMK 05/11/07 Initial release * 1.10 JMK 06/26/07 Fixed ODTH8 check during BLOTF * Removed temp sensor readout from MPR * Updated initialization sequence * Updated timing parameters * 1.20 JMK 09/05/07 Updated clock frequency change * Added ddr3_dimm module * 1.30 JMK 01/23/08 Updated timing parameters * 1.40 JMK 12/02/08 Added support for DDR3-1866 and DDR3-2133 * renamed ddr3_dimm.v to ddr3_module.v and added SODIMM support. * Added multi-chip package model support in ddr3_mcp.v * 1.50 JMK 05/04/08 Added 1866 and 2133 speed grades. * 1.60 MYY 07/10/09 Merging of 1.50 version and pre-1.0 version changes * 1.61 SPH 12/10/09 Only check tIH for cmd_addr if CS# LOW *****************************************************************************************/ // DO NOT CHANGE THE TIMESCALE // MAKE SURE YOUR SIMULATOR USES "PS" RESOLUTION `timescale 1ps / 1ps // model flags // `define MODEL_PASR module ddr3_model_c3( rst_n, ck, ck_n, cke, cs_n, ras_n, cas_n, we_n, dm_tdqs, ba, addr, dq, dqs, dqs_n, tdqs_n, odt ); `include "ddr3_model_parameters_c3.vh" parameter check_strict_mrbits = 1; parameter check_strict_timing = 1; parameter feature_pasr = 1; parameter feature_truebl4 = 0; // text macros `define DQ_PER_DQS DQ_BITS/DQS_BITS `define BANKS (1<<BA_BITS) `define MAX_BITS (BA_BITS+ROW_BITS+COL_BITS-BL_BITS) `define MAX_SIZE (1<<(BA_BITS+ROW_BITS+COL_BITS-BL_BITS)) `define MEM_SIZE (1<<MEM_BITS) `define MAX_PIPE 4*CL_MAX // Declare Ports input rst_n; input ck; input ck_n; input cke; input cs_n; input ras_n; input cas_n; input we_n; inout [DM_BITS-1:0] dm_tdqs; input [BA_BITS-1:0] ba; input [ADDR_BITS-1:0] addr; inout [DQ_BITS-1:0] dq; inout [DQS_BITS-1:0] dqs; inout [DQS_BITS-1:0] dqs_n; output [DQS_BITS-1:0] tdqs_n; input odt; // clock jitter real tck_avg; time tck_sample [TDLLK-1:0]; time tch_sample [TDLLK-1:0]; time tcl_sample [TDLLK-1:0]; time tck_i; time tch_i; time tcl_i; real tch_avg; real tcl_avg; time tm_ck_pos; time tm_ck_neg; real tjit_per_rtime; integer tjit_cc_time; real terr_nper_rtime; //DDR3 clock jitter variables real tjit_ch_rtime; real duty_cycle; // clock skew real out_delay; integer dqsck [DQS_BITS-1:0]; integer dqsck_min; integer dqsck_max; integer dqsq_min; integer dqsq_max; integer seed; // Mode Registers reg [ADDR_BITS-1:0] mode_reg [`BANKS-1:0]; reg burst_order; reg [BL_BITS:0] burst_length; reg blotf; reg truebl4; integer cas_latency; reg dll_reset; reg dll_locked; integer write_recovery; reg low_power; reg dll_en; reg [2:0] odt_rtt_nom; reg [1:0] odt_rtt_wr; reg odt_en; reg dyn_odt_en; reg [1:0] al; integer additive_latency; reg write_levelization; reg duty_cycle_corrector; reg tdqs_en; reg out_en; reg [2:0] pasr; integer cas_write_latency; reg asr; // auto self refresh reg srt; // self refresh temperature range reg [1:0] mpr_select; reg mpr_en; reg odts_readout; integer read_latency; integer write_latency; // cmd encoding parameter // {cs, ras, cas, we} LOAD_MODE = 4'b0000, REFRESH = 4'b0001, PRECHARGE = 4'b0010, ACTIVATE = 4'b0011, WRITE = 4'b0100, READ = 4'b0101, ZQ = 4'b0110, NOP = 4'b0111, // DESEL = 4'b1xxx, PWR_DOWN = 4'b1000, SELF_REF = 4'b1001 ; reg [8*9-1:0] cmd_string [9:0]; initial begin cmd_string[LOAD_MODE] = "Load Mode"; cmd_string[REFRESH ] = "Refresh "; cmd_string[PRECHARGE] = "Precharge"; cmd_string[ACTIVATE ] = "Activate "; cmd_string[WRITE ] = "Write "; cmd_string[READ ] = "Read "; cmd_string[ZQ ] = "ZQ "; cmd_string[NOP ] = "No Op "; cmd_string[PWR_DOWN ] = "Pwr Down "; cmd_string[SELF_REF ] = "Self Ref "; end // command state reg [`BANKS-1:0] active_bank; reg [`BANKS-1:0] auto_precharge_bank; reg [`BANKS-1:0] write_precharge_bank; reg [`BANKS-1:0] read_precharge_bank; reg [ROW_BITS-1:0] active_row [`BANKS-1:0]; reg in_power_down; reg in_self_refresh; reg [3:0] init_mode_reg; reg init_dll_reset; reg init_done; integer init_step; reg zq_set; reg er_trfc_max; reg odt_state; reg odt_state_dly; reg dyn_odt_state; reg dyn_odt_state_dly; reg prev_odt; wire [7:0] calibration_pattern = 8'b10101010; // value returned during mpr pre-defined pattern readout wire [7:0] temp_sensor = 8'h01; // value returned during mpr temp sensor readout reg [1:0] mr_chk; reg rd_bc; integer banki; // cmd timers/counters integer ref_cntr; integer odt_cntr; integer ck_cntr; integer ck_txpr; integer ck_load_mode; integer ck_refresh; integer ck_precharge; integer ck_activate; integer ck_write; integer ck_read; integer ck_zqinit; integer ck_zqoper; integer ck_zqcs; integer ck_power_down; integer ck_slow_exit_pd; integer ck_self_refresh; integer ck_freq_change; integer ck_odt; integer ck_odth8; integer ck_dll_reset; integer ck_cke_cmd; integer ck_bank_write [`BANKS-1:0]; integer ck_bank_read [`BANKS-1:0]; integer ck_group_activate [1:0]; integer ck_group_write [1:0]; integer ck_group_read [1:0]; time tm_txpr; time tm_load_mode; time tm_refresh; time tm_precharge; time tm_activate; time tm_write_end; time tm_power_down; time tm_slow_exit_pd; time tm_self_refresh; time tm_freq_change; time tm_cke_cmd; time tm_ttsinit; time tm_bank_precharge [`BANKS-1:0]; time tm_bank_activate [`BANKS-1:0]; time tm_bank_write_end [`BANKS-1:0]; time tm_bank_read_end [`BANKS-1:0]; time tm_group_activate [1:0]; time tm_group_write_end [1:0]; // pipelines reg [`MAX_PIPE:0] al_pipeline; reg [`MAX_PIPE:0] wr_pipeline; reg [`MAX_PIPE:0] rd_pipeline; reg [`MAX_PIPE:0] odt_pipeline; reg [`MAX_PIPE:0] dyn_odt_pipeline; reg [BL_BITS:0] bl_pipeline [`MAX_PIPE:0]; reg [BA_BITS-1:0] ba_pipeline [`MAX_PIPE:0]; reg [ROW_BITS-1:0] row_pipeline [`MAX_PIPE:0]; reg [COL_BITS-1:0] col_pipeline [`MAX_PIPE:0]; reg prev_cke; // data state reg [BL_MAX*DQ_BITS-1:0] memory_data; reg [BL_MAX*DQ_BITS-1:0] bit_mask; reg [BL_BITS-1:0] burst_position; reg [BL_BITS:0] burst_cntr; reg [DQ_BITS-1:0] dq_temp; reg [31:0] check_write_postamble; reg [31:0] check_write_preamble; reg [31:0] check_write_dqs_high; reg [31:0] check_write_dqs_low; reg [15:0] check_dm_tdipw; reg [63:0] check_dq_tdipw; // data timers/counters time tm_rst_n; time tm_cke; time tm_odt; time tm_tdqss; time tm_dm [15:0]; time tm_dqs [15:0]; time tm_dqs_pos [31:0]; time tm_dqss_pos [31:0]; time tm_dqs_neg [31:0]; time tm_dq [63:0]; time tm_cmd_addr [22:0]; reg [8*7-1:0] cmd_addr_string [22:0]; initial begin cmd_addr_string[ 0] = "CS_N "; cmd_addr_string[ 1] = "RAS_N "; cmd_addr_string[ 2] = "CAS_N "; cmd_addr_string[ 3] = "WE_N "; cmd_addr_string[ 4] = "BA 0 "; cmd_addr_string[ 5] = "BA 1 "; cmd_addr_string[ 6] = "BA 2 "; cmd_addr_string[ 7] = "ADDR 0"; cmd_addr_string[ 8] = "ADDR 1"; cmd_addr_string[ 9] = "ADDR 2"; cmd_addr_string[10] = "ADDR 3"; cmd_addr_string[11] = "ADDR 4"; cmd_addr_string[12] = "ADDR 5"; cmd_addr_string[13] = "ADDR 6"; cmd_addr_string[14] = "ADDR 7"; cmd_addr_string[15] = "ADDR 8"; cmd_addr_string[16] = "ADDR 9"; cmd_addr_string[17] = "ADDR 10"; cmd_addr_string[18] = "ADDR 11"; cmd_addr_string[19] = "ADDR 12"; cmd_addr_string[20] = "ADDR 13"; cmd_addr_string[21] = "ADDR 14"; cmd_addr_string[22] = "ADDR 15"; end reg [8*5-1:0] dqs_string [1:0]; initial begin dqs_string[0] = "DQS "; dqs_string[1] = "DQS_N"; end // Memory Storage `ifdef MAX_MEM parameter RFF_BITS = DQ_BITS*BL_MAX; // %z format uses 8 bytes for every 32 bits or less. parameter RFF_CHUNK = 8 * (RFF_BITS/32 + (RFF_BITS%32 ? 1 : 0)); reg [1024:1] tmp_model_dir; integer memfd[`BANKS-1:0]; initial begin : file_io_open integer bank; if (!$value$plusargs("model_data+%s", tmp_model_dir)) begin tmp_model_dir = "/tmp"; $display( "%m: at time %t WARNING: no +model_data option specified, using /tmp.", $time ); end for (bank = 0; bank < `BANKS; bank = bank + 1) memfd[bank] = open_bank_file(bank); end `else reg [BL_MAX*DQ_BITS-1:0] memory [0:`MEM_SIZE-1]; reg [`MAX_BITS-1:0] address [0:`MEM_SIZE-1]; reg [MEM_BITS:0] memory_index; reg [MEM_BITS:0] memory_used = 0; `endif // receive reg rst_n_in; reg ck_in; reg ck_n_in; reg cke_in; reg cs_n_in; reg ras_n_in; reg cas_n_in; reg we_n_in; reg [15:0] dm_in; reg [2:0] ba_in; reg [15:0] addr_in; reg [63:0] dq_in; reg [31:0] dqs_in; reg odt_in; reg [15:0] dm_in_pos; reg [15:0] dm_in_neg; reg [63:0] dq_in_pos; reg [63:0] dq_in_neg; reg dq_in_valid; reg dqs_in_valid; integer wdqs_cntr; integer wdq_cntr; integer wdqs_pos_cntr [31:0]; reg b2b_write; reg [BL_BITS:0] wr_burst_length; reg [31:0] prev_dqs_in; reg diff_ck; always @(rst_n ) rst_n_in <= #BUS_DELAY rst_n; always @(ck ) ck_in <= #BUS_DELAY ck; always @(ck_n ) ck_n_in <= #BUS_DELAY ck_n; always @(cke ) cke_in <= #BUS_DELAY cke; always @(cs_n ) cs_n_in <= #BUS_DELAY cs_n; always @(ras_n ) ras_n_in <= #BUS_DELAY ras_n; always @(cas_n ) cas_n_in <= #BUS_DELAY cas_n; always @(we_n ) we_n_in <= #BUS_DELAY we_n; always @(dm_tdqs) dm_in <= #BUS_DELAY dm_tdqs; always @(ba ) ba_in <= #BUS_DELAY ba; always @(addr ) addr_in <= #BUS_DELAY addr; always @(dq ) dq_in <= #BUS_DELAY dq; always @(dqs or dqs_n) dqs_in <= #BUS_DELAY (dqs_n<<16) | dqs; always @(odt ) odt_in <= #BUS_DELAY odt; // create internal clock always @(posedge ck_in) diff_ck <= ck_in; always @(posedge ck_n_in) diff_ck <= ~ck_n_in; wire [15:0] dqs_even = dqs_in[15:0]; wire [15:0] dqs_odd = dqs_in[31:16]; wire [3:0] cmd_n_in = !cs_n_in ? {ras_n_in, cas_n_in, we_n_in} : NOP; //deselect = nop // transmit reg dqs_out_en; reg [DQS_BITS-1:0] dqs_out_en_dly; reg dqs_out; reg [DQS_BITS-1:0] dqs_out_dly; reg dq_out_en; reg [DQ_BITS-1:0] dq_out_en_dly; reg [DQ_BITS-1:0] dq_out; reg [DQ_BITS-1:0] dq_out_dly; integer rdqsen_cntr; integer rdqs_cntr; integer rdqen_cntr; integer rdq_cntr; bufif1 buf_dqs [DQS_BITS-1:0] (dqs, dqs_out_dly, dqs_out_en_dly & {DQS_BITS{out_en}}); bufif1 buf_dqs_n [DQS_BITS-1:0] (dqs_n, ~dqs_out_dly, dqs_out_en_dly & {DQS_BITS{out_en}}); bufif1 buf_dq [DQ_BITS-1:0] (dq, dq_out_dly, dq_out_en_dly & {DQ_BITS {out_en}}); assign tdqs_n = {DQS_BITS{1'bz}}; initial begin if (BL_MAX < 2) $display("%m ERROR: BL_MAX parameter must be >= 2. \nBL_MAX = %d", BL_MAX); if ((1<<BO_BITS) > BL_MAX) $display("%m ERROR: 2^BO_BITS cannot be greater than BL_MAX parameter."); $timeformat (-12, 1, " ps", 1); seed = RANDOM_SEED; ck_cntr = 0; end function integer get_rtt_wr; input [1:0] rtt; begin get_rtt_wr = RZQ/{rtt[0], rtt[1], 1'b0}; end endfunction function integer get_rtt_nom; input [2:0] rtt; begin case (rtt) 1: get_rtt_nom = RZQ/4; 2: get_rtt_nom = RZQ/2; 3: get_rtt_nom = RZQ/6; 4: get_rtt_nom = RZQ/12; 5: get_rtt_nom = RZQ/8; default : get_rtt_nom = 0; endcase end endfunction // calculate the absolute value of a real number function real abs_value; input arg; real arg; begin if (arg < 0.0) abs_value = -1.0 * arg; else abs_value = arg; end endfunction function integer ceil; input number; real number; // LMR 4.1.7 // When either operand of a relational expression is a real operand then the other operand shall be converted // to an equivalent real value, and the expression shall be interpreted as a comparison between two real values. if (number > $rtoi(number)) ceil = $rtoi(number) + 1; else ceil = number; endfunction function integer floor; input number; real number; // LMR 4.1.7 // When either operand of a relational expression is a real operand then the other operand shall be converted // to an equivalent real value, and the expression shall be interpreted as a comparison between two real values. if (number < $rtoi(number)) floor = $rtoi(number) - 1; else floor = number; endfunction `ifdef MAX_MEM function integer open_bank_file( input integer bank ); integer fd; reg [2048:1] filename; begin $sformat( filename, "%0s/%m.%0d", tmp_model_dir, bank ); fd = $fopen(filename, "w+"); if (fd == 0) begin $display("%m: at time %0t ERROR: failed to open %0s.", $time, filename); $finish; end else begin if (DEBUG) $display("%m: at time %0t INFO: opening %0s.", $time, filename); open_bank_file = fd; end end endfunction function [RFF_BITS:1] read_from_file( input integer fd, input integer index ); integer code; integer offset; reg [1024:1] msg; reg [RFF_BITS:1] read_value; begin offset = index * RFF_CHUNK; code = $fseek( fd, offset, 0 ); // $fseek returns 0 on success, -1 on failure if (code != 0) begin $display("%m: at time %t ERROR: fseek to %d failed", $time, offset); $finish; end code = $fscanf(fd, "%z", read_value); // $fscanf returns number of items read if (code != 1) begin if ($ferror(fd,msg) != 0) begin $display("%m: at time %t ERROR: fscanf failed at %d", $time, index); $display(msg); $finish; end else read_value = 'hx; end /* when reading from unwritten portions of the file, 0 will be returned. * Use 0 in bit 1 as indicator that invalid data has been read. * A true 0 is encoded as Z. */ if (read_value[1] === 1'bz) // true 0 encoded as Z, data is valid read_value[1] = 1'b0; else if (read_value[1] === 1'b0) // read from file section that has not been written read_value = 'hx; read_from_file = read_value; end endfunction task write_to_file( input integer fd, input integer index, input [RFF_BITS:1] data ); integer code; integer offset; begin offset = index * RFF_CHUNK; code = $fseek( fd, offset, 0 ); if (code != 0) begin $display("%m: at time %t ERROR: fseek to %d failed", $time, offset); $finish; end // encode a valid data if (data[1] === 1'bz) data[1] = 1'bx; else if (data[1] === 1'b0) data[1] = 1'bz; $fwrite( fd, "%z", data ); end endtask `else function get_index; input [`MAX_BITS-1:0] addr; begin : index get_index = 0; for (memory_index=0; memory_index<memory_used; memory_index=memory_index+1) begin if (address[memory_index] == addr) begin get_index = 1; disable index; end end end endfunction `endif task memory_write; input [BA_BITS-1:0] bank; input [ROW_BITS-1:0] row; input [COL_BITS-1:0] col; input [BL_MAX*DQ_BITS-1:0] data; reg [`MAX_BITS-1:0] addr; begin `ifdef MAX_MEM addr = {row, col}/BL_MAX; write_to_file( memfd[bank], addr, data ); `else // chop off the lowest address bits addr = {bank, row, col}/BL_MAX; if (get_index(addr)) begin address[memory_index] = addr; memory[memory_index] = data; end else if (memory_used == `MEM_SIZE) begin $display ("%m: at time %t ERROR: Memory overflow. Write to Address %h with Data %h will be lost.\nYou must increase the MEM_BITS parameter or define MAX_MEM.", $time, addr, data); if (STOP_ON_ERROR) $stop(0); end else begin address[memory_used] = addr; memory[memory_used] = data; memory_used = memory_used + 1; end `endif end endtask task memory_read; input [BA_BITS-1:0] bank; input [ROW_BITS-1:0] row; input [COL_BITS-1:0] col; output [BL_MAX*DQ_BITS-1:0] data; reg [`MAX_BITS-1:0] addr; begin `ifdef MAX_MEM addr = {row, col}/BL_MAX; data = read_from_file( memfd[bank], addr ); `else // chop off the lowest address bits addr = {bank, row, col}/BL_MAX; if (get_index(addr)) begin data = memory[memory_index]; end else begin data = {BL_MAX*DQ_BITS{1'bx}}; end `endif end endtask task set_latency; begin if (al == 0) begin additive_latency = 0; end else begin additive_latency = cas_latency - al; end read_latency = cas_latency + additive_latency; write_latency = cas_write_latency + additive_latency; end endtask // this task will erase the contents of 0 or more banks task erase_banks; input [`BANKS-1:0] banks; //one select bit per bank reg [BA_BITS-1:0] ba; reg [`MAX_BITS-1:0] i; integer bank; begin `ifdef MAX_MEM for (bank = 0; bank < `BANKS; bank = bank + 1) if (banks[bank] === 1'b1) begin $fclose(memfd[bank]); memfd[bank] = open_bank_file(bank); end `else memory_index = 0; i = 0; // remove the selected banks for (memory_index=0; memory_index<memory_used; memory_index=memory_index+1) begin ba = (address[memory_index]>>(ROW_BITS+COL_BITS-BL_BITS)); if (!banks[ba]) begin //bank is selected to keep address[i] = address[memory_index]; memory[i] = memory[memory_index]; i = i + 1; end end // clean up the unused banks for (memory_index=i; memory_index<memory_used; memory_index=memory_index+1) begin address[memory_index] = 'bx; memory[memory_index] = {8*DQ_BITS{1'bx}}; end memory_used = i; `endif end endtask // Before this task runs, the model must be in a valid state for precharge power down and out of reset. // After this task runs, NOP commands must be issued until TZQINIT has been met task initialize; input [ADDR_BITS-1:0] mode_reg0; input [ADDR_BITS-1:0] mode_reg1; input [ADDR_BITS-1:0] mode_reg2; input [ADDR_BITS-1:0] mode_reg3; begin if (DEBUG) $display ("%m: at time %t INFO: Performing Initialization Sequence", $time); cmd_task(1, NOP, 'bx, 'bx); cmd_task(1, ZQ, 'bx, 'h400); //ZQCL cmd_task(1, LOAD_MODE, 3, mode_reg3); cmd_task(1, LOAD_MODE, 2, mode_reg2); cmd_task(1, LOAD_MODE, 1, mode_reg1); cmd_task(1, LOAD_MODE, 0, mode_reg0 | 'h100); // DLL Reset cmd_task(0, NOP, 'bx, 'bx); end endtask task reset_task; integer i; begin // disable inputs dq_in_valid = 0; dqs_in_valid <= 0; wdqs_cntr = 0; wdq_cntr = 0; for (i=0; i<31; i=i+1) begin wdqs_pos_cntr[i] <= 0; end b2b_write <= 0; // disable outputs out_en = 0; dq_out_en = 0; rdq_cntr = 0; dqs_out_en = 0; rdqs_cntr = 0; // disable ODT odt_en = 0; dyn_odt_en = 0; odt_state = 0; dyn_odt_state = 0; // reset bank state active_bank = 0; auto_precharge_bank = 0; read_precharge_bank = 0; write_precharge_bank = 0; // require initialization sequence init_done = 0; mpr_en = 0; init_step = 0; init_mode_reg = 0; init_dll_reset = 0; zq_set = 0; // reset DLL dll_en = 0; dll_reset = 0; dll_locked = 0; // exit power down and self refresh prev_cke = 1'bx; in_power_down = 0; in_self_refresh = 0; // clear pipelines al_pipeline = 0; wr_pipeline = 0; rd_pipeline = 0; odt_pipeline = 0; dyn_odt_pipeline = 0; end endtask parameter SAME_BANK = 2'd0; // same bank, same group parameter DIFF_BANK = 2'd1; // different bank, same group parameter DIFF_GROUP = 2'd2; // different bank, different group task chk_err; input [1:0] relationship; input [BA_BITS-1:0] bank; input [3:0] fromcmd; input [3:0] cmd; reg err; begin // $display ("truebl4 = %d, relationship = %d, fromcmd = %h, cmd = %h", truebl4, relationship, fromcmd, cmd); casex ({truebl4, relationship, fromcmd, cmd}) // load mode {1'bx, DIFF_BANK , LOAD_MODE, LOAD_MODE} : begin if (ck_cntr - ck_load_mode < TMRD) $display ("%m: at time %t ERROR: tMRD violation during %s", $time, cmd_string[cmd]); end {1'bx, DIFF_BANK , LOAD_MODE, READ } : begin if (($time - tm_load_mode < TMOD) || (ck_cntr - ck_load_mode < TMOD_TCK)) $display ("%m: at time %t ERROR: tMOD violation during %s", $time, cmd_string[cmd]); end {1'bx, DIFF_BANK , LOAD_MODE, REFRESH } , {1'bx, DIFF_BANK , LOAD_MODE, PRECHARGE} , {1'bx, DIFF_BANK , LOAD_MODE, ACTIVATE } , {1'bx, DIFF_BANK , LOAD_MODE, ZQ } , {1'bx, DIFF_BANK , LOAD_MODE, PWR_DOWN } , {1'bx, DIFF_BANK , LOAD_MODE, SELF_REF } : begin if (($time - tm_load_mode < TMOD) || (ck_cntr - ck_load_mode < TMOD_TCK)) $display ("%m: at time %t ERROR: tMOD violation during %s", $time, cmd_string[cmd]); end // refresh {1'bx, DIFF_BANK , REFRESH , LOAD_MODE} , {1'bx, DIFF_BANK , REFRESH , REFRESH } , {1'bx, DIFF_BANK , REFRESH , PRECHARGE} , {1'bx, DIFF_BANK , REFRESH , ACTIVATE } , {1'bx, DIFF_BANK , REFRESH , ZQ } , {1'bx, DIFF_BANK , REFRESH , SELF_REF } : begin if ($time - tm_refresh < TRFC_MIN) $display ("%m: at time %t ERROR: tRFC violation during %s", $time, cmd_string[cmd]); end {1'bx, DIFF_BANK , REFRESH , PWR_DOWN } : begin if (ck_cntr - ck_refresh < TREFPDEN) $display ("%m: at time %t ERROR: tREFPDEN violation during %s", $time, cmd_string[cmd]); end // precharge {1'bx, SAME_BANK , PRECHARGE, ACTIVATE } : begin if ($time - tm_bank_precharge[bank] < TRP) $display ("%m: at time %t ERROR: tRP violation during %s to bank %d", $time, cmd_string[cmd], bank); end {1'bx, DIFF_BANK , PRECHARGE, LOAD_MODE} , {1'bx, DIFF_BANK , PRECHARGE, REFRESH } , {1'bx, DIFF_BANK , PRECHARGE, ZQ } , {1'bx, DIFF_BANK , PRECHARGE, SELF_REF } : begin if ($time - tm_precharge < TRP) $display ("%m: at time %t ERROR: tRP violation during %s", $time, cmd_string[cmd]); end {1'bx, DIFF_BANK , PRECHARGE, PWR_DOWN } : ; //tPREPDEN = 1 tCK, can be concurrent with auto precharge // activate {1'bx, SAME_BANK , ACTIVATE , PRECHARGE} : begin if ($time - tm_bank_activate[bank] > TRAS_MAX) $display ("%m: at time %t ERROR: tRAS maximum violation during %s to bank %d", $time, cmd_string[cmd], bank); if ($time - tm_bank_activate[bank] < TRAS_MIN) $display ("%m: at time %t ERROR: tRAS minimum violation during %s to bank %d", $time, cmd_string[cmd], bank);end {1'bx, SAME_BANK , ACTIVATE , ACTIVATE } : begin if ($time - tm_bank_activate[bank] < TRC) $display ("%m: at time %t ERROR: tRC violation during %s to bank %d", $time, cmd_string[cmd], bank); end {1'bx, SAME_BANK , ACTIVATE , WRITE } , {1'bx, SAME_BANK , ACTIVATE , READ } : ; // tRCD is checked outside this task {1'b0, DIFF_BANK , ACTIVATE , ACTIVATE } : begin if (($time - tm_activate < TRRD) || (ck_cntr - ck_activate < TRRD_TCK)) $display ("%m: at time %t ERROR: tRRD violation during %s to bank %d", $time, cmd_string[cmd], bank); end {1'b1, DIFF_BANK , ACTIVATE , ACTIVATE } : begin if (($time - tm_group_activate[bank[1]] < TRRD) || (ck_cntr - ck_group_activate[bank[1]] < TRRD_TCK)) $display ("%m: at time %t ERROR: tRRD violation during %s to bank %d", $time, cmd_string[cmd], bank); end {1'b1, DIFF_GROUP, ACTIVATE , ACTIVATE } : begin if (($time - tm_activate < TRRD_DG) || (ck_cntr - ck_activate < TRRD_DG_TCK)) $display ("%m: at time %t ERROR: tRRD_DG violation during %s to bank %d", $time, cmd_string[cmd], bank); end {1'bx, DIFF_BANK , ACTIVATE , REFRESH } : begin if ($time - tm_activate < TRC) $display ("%m: at time %t ERROR: tRC violation during %s", $time, cmd_string[cmd]); end {1'bx, DIFF_BANK , ACTIVATE , PWR_DOWN } : begin if (ck_cntr - ck_activate < TACTPDEN) $display ("%m: at time %t ERROR: tACTPDEN violation during %s", $time, cmd_string[cmd]); end // write {1'bx, SAME_BANK , WRITE , PRECHARGE} : begin if (($time - tm_bank_write_end[bank] < TWR) || (ck_cntr - ck_bank_write[bank] <= write_latency + burst_length/2)) $display ("%m: at time %t ERROR: tWR violation during %s to bank %d", $time, cmd_string[cmd], bank); end {1'b0, DIFF_BANK , WRITE , WRITE } : begin if (ck_cntr - ck_write < TCCD) $display ("%m: at time %t ERROR: tCCD violation during %s to bank %d", $time, cmd_string[cmd], bank); end {1'b1, DIFF_BANK , WRITE , WRITE } : begin if (ck_cntr - ck_group_write[bank[1]] < TCCD) $display ("%m: at time %t ERROR: tCCD violation during %s to bank %d", $time, cmd_string[cmd], bank); end {1'b0, DIFF_BANK , WRITE , READ } : begin if (ck_cntr - ck_write < write_latency + burst_length/2 + TWTR_TCK - additive_latency) $display ("%m: at time %t ERROR: tWTR violation during %s to bank %d", $time, cmd_string[cmd], bank); end {1'b1, DIFF_BANK , WRITE , READ } : begin if (ck_cntr - ck_group_write[bank[1]] < write_latency + burst_length/2 + TWTR_TCK - additive_latency) $display ("%m: at time %t ERROR: tWTR violation during %s to bank %d", $time, cmd_string[cmd], bank); end {1'b1, DIFF_GROUP, WRITE , WRITE } : begin if (ck_cntr - ck_write < TCCD_DG) $display ("%m: at time %t ERROR: tCCD_DG violation during %s to bank %d", $time, cmd_string[cmd], bank); end {1'b1, DIFF_GROUP, WRITE , READ } : begin if (ck_cntr - ck_write < write_latency + burst_length/2 + TWTR_DG_TCK - additive_latency) $display ("%m: at time %t ERROR: tWTR_DG violation during %s to bank %d", $time, cmd_string[cmd], bank); end {1'bx, DIFF_BANK , WRITE , PWR_DOWN } : begin if (($time - tm_write_end < TWR) || (ck_cntr - ck_write < write_latency + burst_length/2)) $display ("%m: at time %t ERROR: tWRPDEN violation during %s", $time, cmd_string[cmd]); end // read {1'bx, SAME_BANK , READ , PRECHARGE} : begin if (($time - tm_bank_read_end[bank] < TRTP) || (ck_cntr - ck_bank_read[bank] < additive_latency + TRTP_TCK)) $display ("%m: at time %t ERROR: tRTP violation during %s to bank %d", $time, cmd_string[cmd], bank); end {1'b0, DIFF_BANK , READ , WRITE } : ; // tRTW is checked outside this task {1'b1, DIFF_BANK , READ , WRITE } : ; // tRTW is checked outside this task {1'b0, DIFF_BANK , READ , READ } : begin if (ck_cntr - ck_read < TCCD) $display ("%m: at time %t ERROR: tCCD violation during %s to bank %d", $time, cmd_string[cmd], bank); end {1'b1, DIFF_BANK , READ , READ } : begin if (ck_cntr - ck_group_read[bank[1]] < TCCD) $display ("%m: at time %t ERROR: tCCD violation during %s to bank %d", $time, cmd_string[cmd], bank); end {1'b1, DIFF_GROUP, READ , WRITE } : ; // tRTW is checked outside this task {1'b1, DIFF_GROUP, READ , READ } : begin if (ck_cntr - ck_read < TCCD_DG) $display ("%m: at time %t ERROR: tCCD_DG violation during %s to bank %d", $time, cmd_string[cmd], bank); end {1'bx, DIFF_BANK , READ , PWR_DOWN } : begin if (ck_cntr - ck_read < read_latency + 5) $display ("%m: at time %t ERROR: tRDPDEN violation during %s", $time, cmd_string[cmd]); end // zq {1'bx, DIFF_BANK , ZQ , LOAD_MODE} : ; // 1 tCK {1'bx, DIFF_BANK , ZQ , REFRESH } , {1'bx, DIFF_BANK , ZQ , PRECHARGE} , {1'bx, DIFF_BANK , ZQ , ACTIVATE } , {1'bx, DIFF_BANK , ZQ , ZQ } , {1'bx, DIFF_BANK , ZQ , PWR_DOWN } , {1'bx, DIFF_BANK , ZQ , SELF_REF } : begin if (ck_cntr - ck_zqinit < TZQINIT) $display ("%m: at time %t ERROR: tZQinit violation during %s", $time, cmd_string[cmd]); if (ck_cntr - ck_zqoper < TZQOPER) $display ("%m: at time %t ERROR: tZQoper violation during %s", $time, cmd_string[cmd]); if (ck_cntr - ck_zqcs < TZQCS) $display ("%m: at time %t ERROR: tZQCS violation during %s", $time, cmd_string[cmd]); end // power down {1'bx, DIFF_BANK , PWR_DOWN , LOAD_MODE} , {1'bx, DIFF_BANK , PWR_DOWN , REFRESH } , {1'bx, DIFF_BANK , PWR_DOWN , PRECHARGE} , {1'bx, DIFF_BANK , PWR_DOWN , ACTIVATE } , {1'bx, DIFF_BANK , PWR_DOWN , WRITE } , {1'bx, DIFF_BANK , PWR_DOWN , ZQ } : begin if (($time - tm_power_down < TXP) || (ck_cntr - ck_power_down < TXP_TCK)) $display ("%m: at time %t ERROR: tXP violation during %s", $time, cmd_string[cmd]); end {1'bx, DIFF_BANK , PWR_DOWN , READ } : begin if (($time - tm_power_down < TXP) || (ck_cntr - ck_power_down < TXP_TCK)) $display ("%m: at time %t ERROR: tXP violation during %s", $time, cmd_string[cmd]); else if (($time - tm_slow_exit_pd < TXPDLL) || (ck_cntr - ck_slow_exit_pd < TXPDLL_TCK)) $display ("%m: at time %t ERROR: tXPDLL violation during %s", $time, cmd_string[cmd]); end {1'bx, DIFF_BANK , PWR_DOWN , PWR_DOWN } , {1'bx, DIFF_BANK , PWR_DOWN , SELF_REF } : begin if (($time - tm_power_down < TXP) || (ck_cntr - ck_power_down < TXP_TCK)) $display ("%m: at time %t ERROR: tXP violation during %s", $time, cmd_string[cmd]); if ((tm_power_down > tm_refresh) && ($time - tm_refresh < TRFC_MIN)) $display ("%m: at time %t ERROR: tRFC violation during %s", $time, cmd_string[cmd]); if ((tm_refresh > tm_power_down) && (($time - tm_power_down < TXPDLL) || (ck_cntr - ck_power_down < TXPDLL_TCK))) $display ("%m: at time %t ERROR: tXPDLL violation during %s", $time, cmd_string[cmd]); if (($time - tm_cke_cmd < TCKE) || (ck_cntr - ck_cke_cmd < TCKE_TCK)) $display ("%m: at time %t ERROR: tCKE violation on CKE", $time); end // self refresh {1'bx, DIFF_BANK , SELF_REF , LOAD_MODE} , {1'bx, DIFF_BANK , SELF_REF , REFRESH } , {1'bx, DIFF_BANK , SELF_REF , PRECHARGE} , {1'bx, DIFF_BANK , SELF_REF , ACTIVATE } , {1'bx, DIFF_BANK , SELF_REF , WRITE } , {1'bx, DIFF_BANK , SELF_REF , ZQ } : begin if (($time - tm_self_refresh < TXS) || (ck_cntr - ck_self_refresh < TXS_TCK)) $display ("%m: at time %t ERROR: tXS violation during %s", $time, cmd_string[cmd]); end {1'bx, DIFF_BANK , SELF_REF , READ } : begin if (ck_cntr - ck_self_refresh < TXSDLL) $display ("%m: at time %t ERROR: tXSDLL violation during %s", $time, cmd_string[cmd]); end {1'bx, DIFF_BANK , SELF_REF , PWR_DOWN } , {1'bx, DIFF_BANK , SELF_REF , SELF_REF } : begin if (($time - tm_self_refresh < TXS) || (ck_cntr - ck_self_refresh < TXS_TCK)) $display ("%m: at time %t ERROR: tXS violation during %s", $time, cmd_string[cmd]); if (($time - tm_cke_cmd < TCKE) || (ck_cntr - ck_cke_cmd < TCKE_TCK)) $display ("%m: at time %t ERROR: tCKE violation on CKE", $time); end endcase end endtask task cmd_task; input cke; input [2:0] cmd; input [BA_BITS-1:0] bank; input [ADDR_BITS-1:0] addr; reg [`BANKS:0] i; integer j; reg [`BANKS:0] tfaw_cntr; reg [COL_BITS-1:0] col; reg group; begin // tRFC max check if (!er_trfc_max && !in_self_refresh) begin if ($time - tm_refresh > TRFC_MAX && check_strict_timing) begin $display ("%m: at time %t ERROR: tRFC maximum violation during %s", $time, cmd_string[cmd]); er_trfc_max = 1; end end if (cke) begin if ((cmd < NOP) && (cmd != PRECHARGE)) begin if (($time - tm_txpr < TXPR) || (ck_cntr - ck_txpr < TXPR_TCK)) $display ("%m: at time %t ERROR: tXPR violation during %s", $time, cmd_string[cmd]); for (j=0; j<=SELF_REF; j=j+1) begin chk_err(SAME_BANK , bank, j, cmd); chk_err(DIFF_BANK , bank, j, cmd); chk_err(DIFF_GROUP, bank, j, cmd); end end case (cmd) LOAD_MODE : begin if (|odt_pipeline) $display ("%m: at time %t ERROR: ODTL violation during %s", $time, cmd_string[cmd]); if (odt_state) $display ("%m: at time %t ERROR: ODT must be off prior to %s", $time, cmd_string[cmd]); if (|active_bank) begin $display ("%m: at time %t ERROR: %s Failure. All banks must be Precharged.", $time, cmd_string[cmd]); if (STOP_ON_ERROR) $stop(0); end else begin if (DEBUG) $display ("%m: at time %t INFO: %s %d", $time, cmd_string[cmd], bank); if (bank>>2) begin $display ("%m: at time %t ERROR: %s %d Illegal value. Reserved bank bits must be programmed to zero", $time, cmd_string[cmd], bank); end case (bank) 0 : begin // Burst Length if (addr[1:0] == 2'b00) begin burst_length = 8; blotf = 0; truebl4 = 0; if (DEBUG) $display ("%m: at time %t INFO: %s %d Burst Length = %d", $time, cmd_string[cmd], bank, burst_length); end else if (addr[1:0] == 2'b01) begin burst_length = 8; blotf = 1; truebl4 = 0; if (DEBUG) $display ("%m: at time %t INFO: %s %d Burst Length = Select via A12", $time, cmd_string[cmd], bank); end else if (addr[1:0] == 2'b10) begin burst_length = 4; blotf = 0; truebl4 = 0; if (DEBUG) $display ("%m: at time %t INFO: %s %d Burst Length = Fixed %d (chop)", $time, cmd_string[cmd], bank, burst_length); end else if (feature_truebl4 && (addr[1:0] == 2'b11)) begin burst_length = 4; blotf = 0; truebl4 = 1; if (DEBUG) $display ("%m: at time %t INFO: %s %d Burst Length = True %d", $time, cmd_string[cmd], bank, burst_length); end else begin $display ("%m: at time %t ERROR: %s %d Illegal Burst Length = %d", $time, cmd_string[cmd], bank, addr[1:0]); end // Burst Order burst_order = addr[3]; if (!burst_order) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d Burst Order = Sequential", $time, cmd_string[cmd], bank); end else if (burst_order) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d Burst Order = Interleaved", $time, cmd_string[cmd], bank); end else begin $display ("%m: at time %t ERROR: %s %d Illegal Burst Order = %d", $time, cmd_string[cmd], bank, burst_order); end // CAS Latency cas_latency = {addr[2],addr[6:4]} + 4; set_latency; if ((cas_latency >= CL_MIN) && (cas_latency <= CL_MAX)) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d CAS Latency = %d", $time, cmd_string[cmd], bank, cas_latency); end else begin $display ("%m: at time %t ERROR: %s %d Illegal CAS Latency = %d", $time, cmd_string[cmd], bank, cas_latency); end // Reserved if (addr[7] !== 0 && check_strict_mrbits) begin $display ("%m: at time %t ERROR: %s %d Illegal value. Reserved address bits must be programmed to zero", $time, cmd_string[cmd], bank); end // DLL Reset dll_reset = addr[8]; if (!dll_reset) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d DLL Reset = Normal", $time, cmd_string[cmd], bank); end else if (dll_reset) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d DLL Reset = Reset DLL", $time, cmd_string[cmd], bank); dll_locked = 0; init_dll_reset = 1; ck_dll_reset <= ck_cntr; end else begin $display ("%m: at time %t ERROR: %s %d Illegal DLL Reset = %d", $time, cmd_string[cmd], bank, dll_reset); end // Write Recovery if (addr[11:9] == 0) begin write_recovery = 16; end else if (addr[11:9] < 4) begin write_recovery = addr[11:9] + 4; end else begin write_recovery = 2*addr[11:9]; end if ((write_recovery >= WR_MIN) && (write_recovery <= WR_MAX)) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d Write Recovery = %d", $time, cmd_string[cmd], bank, write_recovery); end else begin $display ("%m: at time %t ERROR: %s %d Illegal Write Recovery = %d", $time, cmd_string[cmd], bank, write_recovery); end // Power Down Mode low_power = !addr[12]; if (!low_power) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d Power Down Mode = DLL on", $time, cmd_string[cmd], bank); end else if (low_power) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d Power Down Mode = DLL off", $time, cmd_string[cmd], bank); end else begin $display ("%m: at time %t ERROR: %s %d Illegal Power Down Mode = %d", $time, cmd_string[cmd], bank, low_power); end // Reserved if (ADDR_BITS>13 && addr[13] !== 0 && check_strict_mrbits) begin $display ("%m: at time %t ERROR: %s %d Illegal value. Reserved address bits must be programmed to zero", $time, cmd_string[cmd], bank); end end 1 : begin // DLL Enable dll_en = !addr[0]; if (!dll_en) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d DLL Enable = Disabled", $time, cmd_string[cmd], bank); if (check_strict_mrbits) $display ("%m: at time %t WARNING: %s %d DLL off mode is not modeled", $time, cmd_string[cmd], bank); end else if (dll_en) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d DLL Enable = Enabled", $time, cmd_string[cmd], bank); end else begin $display ("%m: at time %t ERROR: %s %d Illegal DLL Enable = %d", $time, cmd_string[cmd], bank, dll_en); end // Output Drive Strength if ({addr[5], addr[1]} == 2'b00) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d Output Drive Strength = %d Ohm", $time, cmd_string[cmd], bank, RZQ/6); end else if ({addr[5], addr[1]} == 2'b01) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d Output Drive Strength = %d Ohm", $time, cmd_string[cmd], bank, RZQ/7); end else if ({addr[5], addr[1]} == 2'b11) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d Output Drive Strength = %d Ohm", $time, cmd_string[cmd], bank, RZQ/5); end else begin $display ("%m: at time %t ERROR: %s %d Illegal Output Drive Strength = %d", $time, cmd_string[cmd], bank, {addr[5], addr[1]}); end // ODT Rtt (Rtt_NOM) odt_rtt_nom = {addr[9], addr[6], addr[2]}; if (odt_rtt_nom == 3'b000) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d ODT Rtt = Disabled", $time, cmd_string[cmd], bank); odt_en = 0; end else if ((odt_rtt_nom < 4) || ((!addr[7] || (addr[7] && addr[12])) && (odt_rtt_nom < 6))) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d ODT Rtt = %d Ohm", $time, cmd_string[cmd], bank, get_rtt_nom(odt_rtt_nom)); odt_en = 1; end else begin $display ("%m: at time %t ERROR: %s %d Illegal ODT Rtt = %d", $time, cmd_string[cmd], bank, odt_rtt_nom); odt_en = 0; end // Report the additive latency value al = addr[4:3]; set_latency; if (al == 0) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d Additive Latency = %d", $time, cmd_string[cmd], bank, al); end else if ((al >= AL_MIN) && (al <= AL_MAX)) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d Additive Latency = CL - %d", $time, cmd_string[cmd], bank, al); end else begin $display ("%m: at time %t ERROR: %s %d Illegal Additive Latency = %d", $time, cmd_string[cmd], bank, al); end // Write Levelization write_levelization = addr[7]; if (!write_levelization) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d Write Levelization = Disabled", $time, cmd_string[cmd], bank); end else if (write_levelization) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d Write Levelization = Enabled", $time, cmd_string[cmd], bank); end else begin $display ("%m: at time %t ERROR: %s %d Illegal Write Levelization = %d", $time, cmd_string[cmd], bank, write_levelization); end // Reserved if (addr[8] !== 0 && check_strict_mrbits) begin $display ("%m: at time %t ERROR: %s %d Illegal value. Reserved address bits must be programmed to zero", $time, cmd_string[cmd], bank); end // Reserved if (addr[10] !== 0 && check_strict_mrbits) begin $display ("%m: at time %t ERROR: %s %d Illegal value. Reserved address bits must be programmed to zero", $time, cmd_string[cmd], bank); end // TDQS Enable tdqs_en = addr[11]; if (!tdqs_en) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d TDQS Enable = Disabled", $time, cmd_string[cmd], bank); end else if (tdqs_en) begin if (8 == DQ_BITS) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d TDQS Enable = Enabled", $time, cmd_string[cmd], bank); end else begin $display ("%m: at time %t WARNING: %s %d Illegal TDQS Enable. TDQS only exists on a x8 part", $time, cmd_string[cmd], bank); tdqs_en = 0; end end else begin $display ("%m: at time %t ERROR: %s %d Illegal TDQS Enable = %d", $time, cmd_string[cmd], bank, tdqs_en); end // Output Enable out_en = !addr[12]; if (!out_en) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d Qoff = Disabled", $time, cmd_string[cmd], bank); end else if (out_en) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d Qoff = Enabled", $time, cmd_string[cmd], bank); end else begin $display ("%m: at time %t ERROR: %s %d Illegal Qoff = %d", $time, cmd_string[cmd], bank, out_en); end // Reserved if (ADDR_BITS>13 && addr[13] !== 0 && check_strict_mrbits) begin $display ("%m: at time %t ERROR: %s %d Illegal value. Reserved address bits must be programmed to zero", $time, cmd_string[cmd], bank); end end 2 : begin if (feature_pasr) begin // Partial Array Self Refresh pasr = addr[2:0]; case (pasr) 3'b000 : if (DEBUG) $display ("%m: at time %t INFO: %s %d Partial Array Self Refresh = Bank 0-7", $time, cmd_string[cmd], bank); 3'b001 : if (DEBUG) $display ("%m: at time %t INFO: %s %d Partial Array Self Refresh = Bank 0-3", $time, cmd_string[cmd], bank); 3'b010 : if (DEBUG) $display ("%m: at time %t INFO: %s %d Partial Array Self Refresh = Bank 0-1", $time, cmd_string[cmd], bank); 3'b011 : if (DEBUG) $display ("%m: at time %t INFO: %s %d Partial Array Self Refresh = Bank 0", $time, cmd_string[cmd], bank); 3'b100 : if (DEBUG) $display ("%m: at time %t INFO: %s %d Partial Array Self Refresh = Bank 2-7", $time, cmd_string[cmd], bank); 3'b101 : if (DEBUG) $display ("%m: at time %t INFO: %s %d Partial Array Self Refresh = Bank 4-7", $time, cmd_string[cmd], bank); 3'b110 : if (DEBUG) $display ("%m: at time %t INFO: %s %d Partial Array Self Refresh = Bank 6-7", $time, cmd_string[cmd], bank); 3'b111 : if (DEBUG) $display ("%m: at time %t INFO: %s %d Partial Array Self Refresh = Bank 7", $time, cmd_string[cmd], bank); default : $display ("%m: at time %t ERROR: %s %d Illegal Partial Array Self Refresh = %d", $time, cmd_string[cmd], bank, pasr); endcase end else if (addr[2:0] !== 0 && check_strict_mrbits) begin $display ("%m: at time %t ERROR: %s %d Illegal value. Reserved address bits must be programmed to zero", $time, cmd_string[cmd], bank); end // CAS Write Latency cas_write_latency = addr[5:3]+5; set_latency; if ((cas_write_latency >= CWL_MIN) && (cas_write_latency <= CWL_MAX)) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d CAS Write Latency = %d", $time, cmd_string[cmd], bank, cas_write_latency); end else begin $display ("%m: at time %t ERROR: %s %d Illegal CAS Write Latency = %d", $time, cmd_string[cmd], bank, cas_write_latency); end // Auto Self Refresh Method asr = addr[6]; if (!asr) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d Auto Self Refresh = Disabled", $time, cmd_string[cmd], bank); end else if (asr) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d Auto Self Refresh = Enabled", $time, cmd_string[cmd], bank); if (check_strict_mrbits) $display ("%m: at time %t WARNING: %s %d Auto Self Refresh is not modeled", $time, cmd_string[cmd], bank); end else begin $display ("%m: at time %t ERROR: %s %d Illegal Auto Self Refresh = %d", $time, cmd_string[cmd], bank, asr); end // Self Refresh Temperature srt = addr[7]; if (!srt) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d Self Refresh Temperature = Normal", $time, cmd_string[cmd], bank); end else if (srt) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d Self Refresh Temperature = Extended", $time, cmd_string[cmd], bank); if (check_strict_mrbits) $display ("%m: at time %t WARNING: %s %d Self Refresh Temperature is not modeled", $time, cmd_string[cmd], bank); end else begin $display ("%m: at time %t ERROR: %s %d Illegal Self Refresh Temperature = %d", $time, cmd_string[cmd], bank, srt); end if (asr && srt) $display ("%m: at time %t ERROR: %s %d SRT must be set to 0 when ASR is enabled.", $time, cmd_string[cmd], bank); // Reserved if (addr[8] !== 0 && check_strict_mrbits) begin $display ("%m: at time %t ERROR: %s %d Illegal value. Reserved address bits must be programmed to zero", $time, cmd_string[cmd], bank); end // Dynamic ODT (Rtt_WR) odt_rtt_wr = addr[10:9]; if (odt_rtt_wr == 2'b00) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d Dynamic ODT = Disabled", $time, cmd_string[cmd], bank); dyn_odt_en = 0; end else if ((odt_rtt_wr > 0) && (odt_rtt_wr < 3)) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d Dynamic ODT Rtt = %d Ohm", $time, cmd_string[cmd], bank, get_rtt_wr(odt_rtt_wr)); dyn_odt_en = 1; end else begin $display ("%m: at time %t ERROR: %s %d Illegal Dynamic ODT = %d", $time, cmd_string[cmd], bank, odt_rtt_wr); dyn_odt_en = 0; end // Reserved if (ADDR_BITS>13 && addr[13:11] !== 0 && check_strict_mrbits) begin $display ("%m: at time %t ERROR: %s %d Illegal value. Reserved address bits must be programmed to zero", $time, cmd_string[cmd], bank); end end 3 : begin mpr_select = addr[1:0]; // MultiPurpose Register Select if (mpr_select == 2'b00) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d MultiPurpose Register Select = Pre-defined pattern", $time, cmd_string[cmd], bank); end else begin if (check_strict_mrbits) $display ("%m: at time %t ERROR: %s %d Illegal MultiPurpose Register Select = %d", $time, cmd_string[cmd], bank, mpr_select); end // MultiPurpose Register Enable mpr_en = addr[2]; if (!mpr_en) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d MultiPurpose Register Enable = Disabled", $time, cmd_string[cmd], bank); end else if (mpr_en) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d MultiPurpose Register Enable = Enabled", $time, cmd_string[cmd], bank); end else begin $display ("%m: at time %t ERROR: %s %d Illegal MultiPurpose Register Enable = %d", $time, cmd_string[cmd], bank, mpr_en); end // Reserved if (ADDR_BITS>13 && addr[13:3] !== 0 && check_strict_mrbits) begin $display ("%m: at time %t ERROR: %s %d Illegal value. Reserved address bits must be programmed to zero", $time, cmd_string[cmd], bank); end end endcase if (dyn_odt_en && write_levelization) $display ("%m: at time %t ERROR: Dynamic ODT is not available during Write Leveling mode.", $time); init_mode_reg[bank] = 1; mode_reg[bank] = addr; tm_load_mode <= $time; ck_load_mode <= ck_cntr; end end REFRESH : begin if (mpr_en) begin $display ("%m: at time %t ERROR: %s Failure. Multipurpose Register must be disabled.", $time, cmd_string[cmd]); if (STOP_ON_ERROR) $stop(0); end else if (|active_bank) begin $display ("%m: at time %t ERROR: %s Failure. All banks must be Precharged.", $time, cmd_string[cmd]); if (STOP_ON_ERROR) $stop(0); end else begin if (DEBUG) $display ("%m: at time %t INFO: %s", $time, cmd_string[cmd]); er_trfc_max = 0; ref_cntr = ref_cntr + 1; tm_refresh <= $time; ck_refresh <= ck_cntr; end end PRECHARGE : begin if (addr[AP]) begin if (DEBUG) $display ("%m: at time %t INFO: %s All", $time, cmd_string[cmd]); end // PRECHARGE command will be treated as a NOP if there is no open row in that bank (idle state), // or if the previously open row is already in the process of precharging if (|active_bank) begin if (($time - tm_txpr < TXPR) || (ck_cntr - ck_txpr < TXPR_TCK)) $display ("%m: at time %t ERROR: tXPR violation during %s", $time, cmd_string[cmd]); if (mpr_en) begin $display ("%m: at time %t ERROR: %s Failure. Multipurpose Register must be disabled.", $time, cmd_string[cmd]); if (STOP_ON_ERROR) $stop(0); end else begin for (i=0; i<`BANKS; i=i+1) begin if (active_bank[i]) begin if (addr[AP] || (i == bank)) begin for (j=0; j<=SELF_REF; j=j+1) begin chk_err(SAME_BANK, i, j, cmd); chk_err(DIFF_BANK, i, j, cmd); end if (auto_precharge_bank[i]) begin $display ("%m: at time %t ERROR: %s Failure. Auto Precharge is scheduled to bank %d.", $time, cmd_string[cmd], i); if (STOP_ON_ERROR) $stop(0); end else begin if (DEBUG) $display ("%m: at time %t INFO: %s bank %d", $time, cmd_string[cmd], i); active_bank[i] = 1'b0; tm_bank_precharge[i] <= $time; tm_precharge <= $time; ck_precharge <= ck_cntr; end end end end end end end ACTIVATE : begin tfaw_cntr = 0; for (i=0; i<`BANKS; i=i+1) begin if ($time - tm_bank_activate[i] < TFAW) begin tfaw_cntr = tfaw_cntr + 1; end end if (tfaw_cntr > 3) begin $display ("%m: at time %t ERROR: tFAW violation during %s to bank %d", $time, cmd_string[cmd], bank); end if (mpr_en) begin $display ("%m: at time %t ERROR: %s Failure. Multipurpose Register must be disabled.", $time, cmd_string[cmd]); if (STOP_ON_ERROR) $stop(0); end else if (!init_done) begin $display ("%m: at time %t ERROR: %s Failure. Initialization sequence is not complete.", $time, cmd_string[cmd]); if (STOP_ON_ERROR) $stop(0); end else if (active_bank[bank]) begin $display ("%m: at time %t ERROR: %s Failure. Bank %d must be Precharged.", $time, cmd_string[cmd], bank); if (STOP_ON_ERROR) $stop(0); end else begin if (addr >= 1<<ROW_BITS) begin $display ("%m: at time %t WARNING: row = %h does not exist. Maximum row = %h", $time, addr, (1<<ROW_BITS)-1); end if (DEBUG) $display ("%m: at time %t INFO: %s bank %d row %h", $time, cmd_string[cmd], bank, addr); active_bank[bank] = 1'b1; active_row[bank] = addr; tm_group_activate[bank[1]] <= $time; tm_activate <= $time; tm_bank_activate[bank] <= $time; ck_group_activate[bank[1]] <= ck_cntr; ck_activate <= ck_cntr; end end WRITE : begin if ((!rd_bc && blotf) || (burst_length == 4)) begin // BL=4 if (truebl4) begin if (ck_cntr - ck_group_read[bank[1]] < read_latency + TCCD/2 + 2 - write_latency) $display ("%m: at time %t ERROR: tRTW violation during %s to bank %d", $time, cmd_string[cmd], bank); if (ck_cntr - ck_read < read_latency + TCCD_DG/2 + 2 - write_latency) $display ("%m: at time %t ERROR: tRTW_DG violation during %s to bank %d", $time, cmd_string[cmd], bank); end else begin if (ck_cntr - ck_read < read_latency + TCCD/2 + 2 - write_latency) $display ("%m: at time %t ERROR: tRTW violation during %s to bank %d", $time, cmd_string[cmd], bank); end end else begin // BL=8 if (ck_cntr - ck_read < read_latency + TCCD + 2 - write_latency) $display ("%m: at time %t ERROR: tRTW violation during %s to bank %d", $time, cmd_string[cmd], bank); end if (mpr_en) begin $display ("%m: at time %t ERROR: %s Failure. Multipurpose Register must be disabled.", $time, cmd_string[cmd]); if (STOP_ON_ERROR) $stop(0); end else if (!init_done) begin $display ("%m: at time %t ERROR: %s Failure. Initialization sequence is not complete.", $time, cmd_string[cmd]); if (STOP_ON_ERROR) $stop(0); end else if (!active_bank[bank]) begin if (check_strict_timing) $display ("%m: at time %t ERROR: %s Failure. Bank %d must be Activated.", $time, cmd_string[cmd], bank); if (STOP_ON_ERROR) $stop(0); end else if (auto_precharge_bank[bank]) begin $display ("%m: at time %t ERROR: %s Failure. Auto Precharge is scheduled to bank %d.", $time, cmd_string[cmd], bank); if (STOP_ON_ERROR) $stop(0); end else if (ck_cntr - ck_write < burst_length/2) begin $display ("%m: at time %t ERROR: %s Failure. Illegal burst interruption.", $time, cmd_string[cmd]); if (STOP_ON_ERROR) $stop(0); end else begin if (addr[AP]) begin auto_precharge_bank[bank] = 1'b1; write_precharge_bank[bank] = 1'b1; end col = {addr[BC-1:AP+1], addr[AP-1:0]}; // assume BC > AP if (col >= 1<<COL_BITS) begin $display ("%m: at time %t WARNING: col = %h does not exist. Maximum col = %h", $time, col, (1<<COL_BITS)-1); end if ((!addr[BC] && blotf) || (burst_length == 4)) begin // BL=4 col = col & -4; end else begin // BL=8 col = col & -8; end if (DEBUG) $display ("%m: at time %t INFO: %s bank %d col %h, auto precharge %d", $time, cmd_string[cmd], bank, col, addr[AP]); wr_pipeline[2*write_latency + 1] = 1; ba_pipeline[2*write_latency + 1] = bank; row_pipeline[2*write_latency + 1] = active_row[bank]; col_pipeline[2*write_latency + 1] = col; if ((!addr[BC] && blotf) || (burst_length == 4)) begin // BL=4 bl_pipeline[2*write_latency + 1] = 4; if (mpr_en && col%4) begin $display ("%m: at time %t WARNING: col[1:0] must be set to 2'b00 during a BL4 Multipurpose Register read", $time); end end else begin // BL=8 bl_pipeline[2*write_latency + 1] = 8; if (odt_in) begin ck_odth8 <= ck_cntr; end end for (j=0; j<(burst_length + 4); j=j+1) begin dyn_odt_pipeline[2*(write_latency - 2) + j] = 1'b1; // ODTLcnw = WL - 2, ODTLcwn = BL/2 + 2 end ck_bank_write[bank] <= ck_cntr; ck_group_write[bank[1]] <= ck_cntr; ck_write <= ck_cntr; end end READ : begin if (!dll_locked) $display ("%m: at time %t WARNING: tDLLK violation during %s.", $time, cmd_string[cmd]); if (mpr_en && (addr[1:0] != 2'b00)) begin $display ("%m: at time %t ERROR: %s Failure. addr[1:0] must be zero during Multipurpose Register Read.", $time, cmd_string[cmd]); if (STOP_ON_ERROR) $stop(0); end else if (!init_done) begin $display ("%m: at time %t ERROR: %s Failure. Initialization sequence is not complete.", $time, cmd_string[cmd]); if (STOP_ON_ERROR) $stop(0); end else if (!active_bank[bank] && !mpr_en) begin if (check_strict_timing) $display ("%m: at time %t ERROR: %s Failure. Bank %d must be Activated.", $time, cmd_string[cmd], bank); if (STOP_ON_ERROR) $stop(0); end else if (auto_precharge_bank[bank]) begin $display ("%m: at time %t ERROR: %s Failure. Auto Precharge is scheduled to bank %d.", $time, cmd_string[cmd], bank); if (STOP_ON_ERROR) $stop(0); end else if (ck_cntr - ck_read < burst_length/2) begin $display ("%m: at time %t ERROR: %s Failure. Illegal burst interruption.", $time, cmd_string[cmd]); if (STOP_ON_ERROR) $stop(0); end else begin if (addr[AP] && !mpr_en) begin auto_precharge_bank[bank] = 1'b1; read_precharge_bank[bank] = 1'b1; end col = {addr[BC-1:AP+1], addr[AP-1:0]}; // assume BC > AP if (col >= 1<<COL_BITS) begin $display ("%m: at time %t WARNING: col = %h does not exist. Maximum col = %h", $time, col, (1<<COL_BITS)-1); end if (DEBUG) $display ("%m: at time %t INFO: %s bank %d col %h, auto precharge %d", $time, cmd_string[cmd], bank, col, addr[AP]); rd_pipeline[2*read_latency - 1] = 1; ba_pipeline[2*read_latency - 1] = bank; row_pipeline[2*read_latency - 1] = active_row[bank]; col_pipeline[2*read_latency - 1] = col; if ((!addr[BC] && blotf) || (burst_length == 4)) begin // BL=4 bl_pipeline[2*read_latency - 1] = 4; if (mpr_en && col%4) begin $display ("%m: at time %t WARNING: col[1:0] must be set to 2'b00 during a BL4 Multipurpose Register read", $time); end end else begin // BL=8 bl_pipeline[2*read_latency - 1] = 8; if (mpr_en && col%8) begin $display ("%m: at time %t WARNING: col[2:0] must be set to 3'b000 during a BL8 Multipurpose Register read", $time); end end rd_bc = addr[BC]; ck_bank_read[bank] <= ck_cntr; ck_group_read[bank[1]] <= ck_cntr; ck_read <= ck_cntr; end end ZQ : begin if (mpr_en) begin $display ("%m: at time %t ERROR: %s Failure. Multipurpose Register must be disabled.", $time, cmd_string[cmd]); if (STOP_ON_ERROR) $stop(0); end else if (|active_bank) begin $display ("%m: at time %t ERROR: %s Failure. All banks must be Precharged.", $time, cmd_string[cmd]); if (STOP_ON_ERROR) $stop(0); end else begin if (DEBUG) $display ("%m: at time %t INFO: %s long = %d", $time, cmd_string[cmd], addr[AP]); if (addr[AP]) begin zq_set = 1; if (init_done) begin ck_zqoper <= ck_cntr; end else begin ck_zqinit <= ck_cntr; end end else begin ck_zqcs <= ck_cntr; end end end NOP: begin if (in_power_down) begin if (($time - tm_freq_change < TCKSRX) || (ck_cntr - ck_freq_change < TCKSRX_TCK)) $display ("%m: at time %t ERROR: tCKSRX violation during Power Down Exit", $time); if ($time - tm_cke_cmd > TPD_MAX) $display ("%m: at time %t ERROR: tPD maximum violation during Power Down Exit", $time); if (DEBUG) $display ("%m: at time %t INFO: Power Down Exit", $time); in_power_down = 0; if ((active_bank == 0) && low_power) begin // precharge power down with dll off if (ck_cntr - ck_odt < write_latency - 1) $display ("%m: at time %t WARNING: tANPD violation during Power Down Exit. Synchronous or asynchronous change in termination resistance is possible.", $time); tm_slow_exit_pd <= $time; ck_slow_exit_pd <= ck_cntr; end tm_power_down <= $time; ck_power_down <= ck_cntr; end if (in_self_refresh) begin if (($time - tm_freq_change < TCKSRX) || (ck_cntr - ck_freq_change < TCKSRX_TCK)) $display ("%m: at time %t ERROR: tCKSRX violation during Self Refresh Exit", $time); if (ck_cntr - ck_cke_cmd < TCKESR_TCK) $display ("%m: at time %t ERROR: tCKESR violation during Self Refresh Exit", $time); if ($time - tm_cke < TISXR) $display ("%m: at time %t ERROR: tISXR violation during Self Refresh Exit", $time); if (DEBUG) $display ("%m: at time %t INFO: Self Refresh Exit", $time); in_self_refresh = 0; ck_dll_reset <= ck_cntr; ck_self_refresh <= ck_cntr; tm_self_refresh <= $time; tm_refresh <= $time; end end endcase if ((prev_cke !== 1) && (cmd !== NOP)) begin $display ("%m: at time %t ERROR: NOP or Deselect is required when CKE goes active.", $time); end if (!init_done) begin case (init_step) 0 : begin if ($time - tm_rst_n < 500000000 && check_strict_timing) $display ("%m at time %t WARNING: 500 us is required after RST_N goes inactive before CKE goes active.", $time); tm_txpr <= $time; ck_txpr <= ck_cntr; init_step = init_step + 1; end 1 : if (dll_en) init_step = init_step + 1; 2 : begin if (&init_mode_reg && init_dll_reset && zq_set) begin if (DEBUG) $display ("%m: at time %t INFO: Initialization Sequence is complete", $time); init_done = 1; end end endcase end end else if (prev_cke) begin if ((!init_done) && (init_step > 1)) begin $display ("%m: at time %t ERROR: CKE must remain active until the initialization sequence is complete.", $time); if (STOP_ON_ERROR) $stop(0); end case (cmd) REFRESH : begin if ($time - tm_txpr < TXPR) $display ("%m: at time %t ERROR: tXPR violation during %s", $time, cmd_string[SELF_REF]); for (j=0; j<=SELF_REF; j=j+1) begin chk_err(DIFF_BANK, bank, j, SELF_REF); end if (mpr_en) begin $display ("%m: at time %t ERROR: Self Refresh Failure. Multipurpose Register must be disabled.", $time); if (STOP_ON_ERROR) $stop(0); end else if (|active_bank) begin $display ("%m: at time %t ERROR: Self Refresh Failure. All banks must be Precharged.", $time); if (STOP_ON_ERROR) $stop(0); end else if (odt_state) begin $display ("%m: at time %t ERROR: Self Refresh Failure. ODT must be off prior to entering Self Refresh", $time); if (STOP_ON_ERROR) $stop(0); end else if (!init_done) begin $display ("%m: at time %t ERROR: Self Refresh Failure. Initialization sequence is not complete.", $time); if (STOP_ON_ERROR) $stop(0); end else begin if (DEBUG) $display ("%m: at time %t INFO: Self Refresh Enter", $time); if (feature_pasr) // Partial Array Self Refresh case (pasr) 3'b000 : ;//keep Bank 0-7 3'b001 : begin if (DEBUG) $display("%m: at time %t INFO: Banks 4-7 will be lost due to Partial Array Self Refresh", $time); erase_banks(8'hF0); end 3'b010 : begin if (DEBUG) $display("%m: at time %t INFO: Banks 2-7 will be lost due to Partial Array Self Refresh", $time); erase_banks(8'hFC); end 3'b011 : begin if (DEBUG) $display("%m: at time %t INFO: Banks 1-7 will be lost due to Partial Array Self Refresh", $time); erase_banks(8'hFE); end 3'b100 : begin if (DEBUG) $display("%m: at time %t INFO: Banks 0-1 will be lost due to Partial Array Self Refresh", $time); erase_banks(8'h03); end 3'b101 : begin if (DEBUG) $display("%m: at time %t INFO: Banks 0-3 will be lost due to Partial Array Self Refresh", $time); erase_banks(8'h0F); end 3'b110 : begin if (DEBUG) $display("%m: at time %t INFO: Banks 0-5 will be lost due to Partial Array Self Refresh", $time); erase_banks(8'h3F); end 3'b111 : begin if (DEBUG) $display("%m: at time %t INFO: Banks 0-6 will be lost due to Partial Array Self Refresh", $time); erase_banks(8'h7F); end endcase in_self_refresh = 1; dll_locked = 0; end end NOP : begin // entering precharge power down with dll off and tANPD has not been satisfied if (low_power && (active_bank == 0) && |odt_pipeline) $display ("%m: at time %t WARNING: tANPD violation during %s. Synchronous or asynchronous change in termination resistance is possible.", $time, cmd_string[PWR_DOWN]); if ($time - tm_txpr < TXPR) $display ("%m: at time %t ERROR: tXPR violation during %s", $time, cmd_string[PWR_DOWN]); for (j=0; j<=SELF_REF; j=j+1) begin chk_err(DIFF_BANK, bank, j, PWR_DOWN); end if (mpr_en) begin $display ("%m: at time %t ERROR: Power Down Failure. Multipurpose Register must be disabled.", $time); if (STOP_ON_ERROR) $stop(0); end else if (!init_done) begin $display ("%m: at time %t ERROR: Power Down Failure. Initialization sequence is not complete.", $time); if (STOP_ON_ERROR) $stop(0); end else begin if (DEBUG) begin if (|active_bank) begin $display ("%m: at time %t INFO: Active Power Down Enter", $time); end else begin $display ("%m: at time %t INFO: Precharge Power Down Enter", $time); end end in_power_down = 1; end end default : begin $display ("%m: at time %t ERROR: NOP, Deselect, or Refresh is required when CKE goes inactive.", $time); end endcase end else if (in_self_refresh || in_power_down) begin if ((ck_cntr - ck_cke_cmd <= TCPDED) && (cmd !== NOP)) $display ("%m: at time %t ERROR: tCPDED violation during Power Down or Self Refresh Entry. NOP or Deselect is required.", $time); end prev_cke = cke; end endtask task data_task; reg [BA_BITS-1:0] bank; reg [ROW_BITS-1:0] row; reg [COL_BITS-1:0] col; integer i; integer j; begin if (diff_ck) begin for (i=0; i<32; i=i+1) begin if (dq_in_valid && dll_locked && ($time - tm_dqs_neg[i] < $rtoi(TDSS*tck_avg))) $display ("%m: at time %t ERROR: tDSS violation on %s bit %d", $time, dqs_string[i/16], i%16); if (check_write_dqs_high[i]) $display ("%m: at time %t ERROR: %s bit %d latching edge required during the preceding clock period.", $time, dqs_string[i/16], i%16); end check_write_dqs_high <= 0; end else begin for (i=0; i<32; i=i+1) begin if (dll_locked && dq_in_valid) begin tm_tdqss = abs_value(1.0*tm_ck_pos - tm_dqss_pos[i]); if ((tm_tdqss < tck_avg/2.0) && (tm_tdqss > TDQSS*tck_avg)) $display ("%m: at time %t ERROR: tDQSS violation on %s bit %d", $time, dqs_string[i/16], i%16); end if (check_write_dqs_low[i]) $display ("%m: at time %t ERROR: %s bit %d latching edge required during the preceding clock period", $time, dqs_string[i/16], i%16); end check_write_preamble <= 0; check_write_postamble <= 0; check_write_dqs_low <= 0; end if (wr_pipeline[0] || rd_pipeline[0]) begin bank = ba_pipeline[0]; row = row_pipeline[0]; col = col_pipeline[0]; burst_cntr = 0; memory_read(bank, row, col, memory_data); end // burst counter if (burst_cntr < burst_length) begin burst_position = col ^ burst_cntr; if (!burst_order) begin burst_position[BO_BITS-1:0] = col + burst_cntr; end burst_cntr = burst_cntr + 1; end // write dqs counter if (wr_pipeline[WDQS_PRE + 1]) begin wdqs_cntr = WDQS_PRE + bl_pipeline[WDQS_PRE + 1] + WDQS_PST - 1; end // write dqs if ((wr_pipeline[2]) && (wdq_cntr == 0)) begin //write preamble check_write_preamble <= ({DQS_BITS{1'b1}}<<16) | {DQS_BITS{1'b1}}; end if (wdqs_cntr > 1) begin // write data if ((wdqs_cntr - WDQS_PST)%2) begin check_write_dqs_high <= ({DQS_BITS{1'b1}}<<16) | {DQS_BITS{1'b1}}; end else begin check_write_dqs_low <= ({DQS_BITS{1'b1}}<<16) | {DQS_BITS{1'b1}}; end end if (wdqs_cntr == WDQS_PST) begin // write postamble check_write_postamble <= ({DQS_BITS{1'b1}}<<16) | {DQS_BITS{1'b1}}; end if (wdqs_cntr > 0) begin wdqs_cntr = wdqs_cntr - 1; end // write dq if (dq_in_valid) begin // write data bit_mask = 0; if (diff_ck) begin for (i=0; i<DM_BITS; i=i+1) begin bit_mask = bit_mask | ({`DQ_PER_DQS{~dm_in_neg[i]}}<<(burst_position*DQ_BITS + i*`DQ_PER_DQS)); end memory_data = (dq_in_neg<<(burst_position*DQ_BITS) & bit_mask) | (memory_data & ~bit_mask); end else begin for (i=0; i<DM_BITS; i=i+1) begin bit_mask = bit_mask | ({`DQ_PER_DQS{~dm_in_pos[i]}}<<(burst_position*DQ_BITS + i*`DQ_PER_DQS)); end memory_data = (dq_in_pos<<(burst_position*DQ_BITS) & bit_mask) | (memory_data & ~bit_mask); end dq_temp = memory_data>>(burst_position*DQ_BITS); if (DEBUG) $display ("%m: at time %t INFO: WRITE @ DQS= bank = %h row = %h col = %h data = %h",$time, bank, row, (-1*BL_MAX & col) + burst_position, dq_temp); if (burst_cntr%BL_MIN == 0) begin memory_write(bank, row, col, memory_data); end end if (wr_pipeline[1]) begin wdq_cntr = bl_pipeline[1]; end if (wdq_cntr > 0) begin wdq_cntr = wdq_cntr - 1; dq_in_valid = 1'b1; end else begin dq_in_valid = 1'b0; dqs_in_valid <= 1'b0; for (i=0; i<31; i=i+1) begin wdqs_pos_cntr[i] <= 0; end end if (wr_pipeline[0]) begin b2b_write <= 1'b0; end if (wr_pipeline[2]) begin if (dqs_in_valid) begin b2b_write <= 1'b1; end dqs_in_valid <= 1'b1; wr_burst_length = bl_pipeline[2]; end // read dqs enable counter if (rd_pipeline[RDQSEN_PRE]) begin rdqsen_cntr = RDQSEN_PRE + bl_pipeline[RDQSEN_PRE] + RDQSEN_PST - 1; end if (rdqsen_cntr > 0) begin rdqsen_cntr = rdqsen_cntr - 1; dqs_out_en = 1'b1; end else begin dqs_out_en = 1'b0; end // read dqs counter if (rd_pipeline[RDQS_PRE]) begin rdqs_cntr = RDQS_PRE + bl_pipeline[RDQS_PRE] + RDQS_PST - 1; end // read dqs if (((rd_pipeline>>1 & {RDQS_PRE{1'b1}}) > 0) && (rdq_cntr == 0)) begin //read preamble dqs_out = 1'b0; end else if (rdqs_cntr > RDQS_PST) begin // read data dqs_out = rdqs_cntr - RDQS_PST; end else if (rdqs_cntr > 0) begin // read postamble dqs_out = 1'b0; end else begin dqs_out = 1'b1; end if (rdqs_cntr > 0) begin rdqs_cntr = rdqs_cntr - 1; end // read dq enable counter if (rd_pipeline[RDQEN_PRE]) begin rdqen_cntr = RDQEN_PRE + bl_pipeline[RDQEN_PRE] + RDQEN_PST; end if (rdqen_cntr > 0) begin rdqen_cntr = rdqen_cntr - 1; dq_out_en = 1'b1; end else begin dq_out_en = 1'b0; end // read dq if (rd_pipeline[0]) begin rdq_cntr = bl_pipeline[0]; end if (rdq_cntr > 0) begin // read data if (mpr_en) begin `ifdef MPR_DQ0 // DQ0 output MPR data, other DQ low if (mpr_select == 2'b00) begin // Calibration Pattern dq_temp = {DQS_BITS{{`DQ_PER_DQS-1{1'b0}}, calibration_pattern[burst_position]}}; end else if (odts_readout && (mpr_select == 2'b11)) begin // Temp Sensor (ODTS) dq_temp = {DQS_BITS{{`DQ_PER_DQS-1{1'b0}}, temp_sensor[burst_position]}}; end else begin // Reserved dq_temp = {DQS_BITS{{`DQ_PER_DQS-1{1'b0}}, 1'bx}}; end `else // all DQ output MPR data if (mpr_select == 2'b00) begin // Calibration Pattern dq_temp = {DQS_BITS{{`DQ_PER_DQS{calibration_pattern[burst_position]}}}}; end else if (odts_readout && (mpr_select == 2'b11)) begin // Temp Sensor (ODTS) dq_temp = {DQS_BITS{{`DQ_PER_DQS{temp_sensor[burst_position]}}}}; end else begin // Reserved dq_temp = {DQS_BITS{{`DQ_PER_DQS{1'bx}}}}; end `endif if (DEBUG) $display ("%m: at time %t READ @ DQS MultiPurpose Register %d, col = %d, data = %b", $time, mpr_select, burst_position, dq_temp[0]); end else begin dq_temp = memory_data>>(burst_position*DQ_BITS); if (DEBUG) $display ("%m: at time %t INFO: READ @ DQS= bank = %h row = %h col = %h data = %h",$time, bank, row, (-1*BL_MAX & col) + burst_position, dq_temp); end dq_out = dq_temp; rdq_cntr = rdq_cntr - 1; end else begin dq_out = {DQ_BITS{1'b1}}; end // delay signals prior to output if (RANDOM_OUT_DELAY && (dqs_out_en || (|dqs_out_en_dly) || dq_out_en || (|dq_out_en_dly))) begin for (i=0; i<DQS_BITS; i=i+1) begin // DQSCK requirements // 1.) less than tDQSCK // 2.) greater than -tDQSCK // 3.) cannot change more than tQH + tDQSQ from previous DQS edge dqsck_max = TDQSCK; if (dqsck_max > dqsck[i] + TQH*tck_avg + TDQSQ) begin dqsck_max = dqsck[i] + TQH*tck_avg + TDQSQ; end dqsck_min = -1*TDQSCK; if (dqsck_min < dqsck[i] - TQH*tck_avg - TDQSQ) begin dqsck_min = dqsck[i] - TQH*tck_avg - TDQSQ; end // DQSQ requirements // 1.) less than tDQSQ // 2.) greater than 0 // 3.) greater than tQH from the previous DQS edge dqsq_min = 0; if (dqsq_min < dqsck[i] - TQH*tck_avg) begin dqsq_min = dqsck[i] - TQH*tck_avg; end if (dqsck_min == dqsck_max) begin dqsck[i] = dqsck_min; end else begin dqsck[i] = $dist_uniform(seed, dqsck_min, dqsck_max); end dqsq_max = TDQSQ + dqsck[i]; dqs_out_en_dly[i] <= #(tck_avg/2) dqs_out_en; dqs_out_dly[i] <= #(tck_avg/2 + dqsck[i]) dqs_out; if (!write_levelization) begin for (j=0; j<`DQ_PER_DQS; j=j+1) begin dq_out_en_dly[i*`DQ_PER_DQS + j] <= #(tck_avg/2) dq_out_en; if (dqsq_min == dqsq_max) begin dq_out_dly [i*`DQ_PER_DQS + j] <= #(tck_avg/2 + dqsq_min) dq_out[i*`DQ_PER_DQS + j]; end else begin dq_out_dly [i*`DQ_PER_DQS + j] <= #(tck_avg/2 + $dist_uniform(seed, dqsq_min, dqsq_max)) dq_out[i*`DQ_PER_DQS + j]; end end end end end else begin out_delay = tck_avg/2; dqs_out_en_dly <= #(out_delay) {DQS_BITS{dqs_out_en}}; dqs_out_dly <= #(out_delay) {DQS_BITS{dqs_out }}; if (write_levelization !== 1'b1) begin dq_out_en_dly <= #(out_delay) {DQ_BITS {dq_out_en }}; dq_out_dly <= #(out_delay) {DQ_BITS {dq_out }}; end end end endtask always @ (posedge rst_n_in) begin : reset integer i; if (rst_n_in) begin if ($time < 200000000 && check_strict_timing) $display ("%m at time %t WARNING: 200 us is required before RST_N goes inactive.", $time); if (cke_in !== 1'b0) $display ("%m: at time %t ERROR: CKE must be inactive when RST_N goes inactive.", $time); if ($time - tm_cke < 10000) $display ("%m: at time %t ERROR: CKE must be maintained inactive for 10 ns before RST_N goes inactive.", $time); // clear memory `ifdef MAX_MEM // verification group does not erase memory // for (banki = 0; banki < `BANKS; banki = banki + 1) begin // $fclose(memfd[banki]); // memfd[banki] = open_bank_file(banki); // end `else memory_used <= 0; //erase memory `endif end end always @(negedge rst_n_in or posedge diff_ck or negedge diff_ck) begin : main integer i; if (!rst_n_in) begin reset_task; end else begin if (!in_self_refresh && (diff_ck !== 1'b0) && (diff_ck !== 1'b1)) $display ("%m: at time %t ERROR: CK and CK_N are not allowed to go to an unknown state.", $time); data_task; // Clock Frequency Change is legal: // 1.) During Self Refresh // 2.) During Precharge Power Down (DLL on or off) if (in_self_refresh || (in_power_down && (active_bank == 0))) begin if (diff_ck) begin tjit_per_rtime = $time - tm_ck_pos - tck_avg; end else begin tjit_per_rtime = $time - tm_ck_neg - tck_avg; end if (dll_locked && (abs_value(tjit_per_rtime) > TJIT_PER)) begin if ((tm_ck_pos - tm_cke_cmd < TCKSRE) || (ck_cntr - ck_cke_cmd < TCKSRE_TCK)) $display ("%m: at time %t ERROR: tCKSRE violation during Self Refresh or Precharge Power Down Entry", $time); if (odt_state) begin $display ("%m: at time %t ERROR: Clock Frequency Change Failure. ODT must be off prior to Clock Frequency Change.", $time); if (STOP_ON_ERROR) $stop(0); end else begin if (DEBUG) $display ("%m: at time %t INFO: Clock Frequency Change detected. DLL Reset is Required.", $time); tm_freq_change <= $time; ck_freq_change <= ck_cntr; dll_locked = 0; end end end if (diff_ck) begin // check setup of command signals if ($time > TIS) begin if ($time - tm_cke < TIS) $display ("%m: at time %t ERROR: tIS violation on CKE by %t", $time, tm_cke + TIS - $time); if (cke_in) begin for (i=0; i<22; i=i+1) begin if ($time - tm_cmd_addr[i] < TIS) $display ("%m: at time %t ERROR: tIS violation on %s by %t", $time, cmd_addr_string[i], tm_cmd_addr[i] + TIS - $time); end end end // update current state if (dll_locked) begin if (mr_chk == 0) begin mr_chk = 1; end else if (init_mode_reg[0] && (mr_chk == 1)) begin // check CL value against the clock frequency if (cas_latency*tck_avg < CL_TIME && check_strict_timing) $display ("%m: at time %t ERROR: CAS Latency = %d is illegal @tCK(avg) = %f", $time, cas_latency, tck_avg); // check WR value against the clock frequency if (ceil(write_recovery*tck_avg) < TWR) $display ("%m: at time %t ERROR: Write Recovery = %d is illegal @tCK(avg) = %f", $time, write_recovery, tck_avg); // check the CWL value against the clock frequency if (check_strict_timing) begin case (cas_write_latency) 5 : if (tck_avg < 2500.0) $display ("%m: at time %t ERROR: CWL = %d is illegal @tCK(avg) = %f", $time, cas_write_latency, tck_avg); 6 : if ((tck_avg < 1875.0) || (tck_avg >= 2500.0)) $display ("%m: at time %t ERROR: CWL = %d is illegal @tCK(avg) = %f", $time, cas_write_latency, tck_avg); 7 : if ((tck_avg < 1500.0) || (tck_avg >= 1875.0)) $display ("%m: at time %t ERROR: CWL = %d is illegal @tCK(avg) = %f", $time, cas_write_latency, tck_avg); 8 : if ((tck_avg < 1250.0) || (tck_avg >= 1500.0)) $display ("%m: at time %t ERROR: CWL = %d is illegal @tCK(avg) = %f", $time, cas_write_latency, tck_avg); 9 : if ((tck_avg < 15e3/14) || (tck_avg >= 1250.0)) $display ("%m: at time %t ERROR: CWL = %d is illegal @tCK(avg) = %f", $time, cas_write_latency, tck_avg); 10: if ((tck_avg < 937.5) || (tck_avg >= 15e3/14)) $display ("%m: at time %t ERROR: CWL = %d is illegal @tCK(avg) = %f", $time, cas_write_latency, tck_avg); default : $display ("%m: at time %t ERROR: CWL = %d is illegal @tCK(avg) = %f", $time, cas_write_latency, tck_avg); endcase // check the CL value against the clock frequency if (!valid_cl(cas_latency, cas_write_latency)) $display ("%m: at time %t ERROR: CAS Latency = %d is not valid when CAS Write Latency = %d", $time, cas_latency, cas_write_latency); end mr_chk = 2; end end else if (!in_self_refresh) begin mr_chk = 0; if (ck_cntr - ck_dll_reset == TDLLK) begin dll_locked = 1; end end if (|auto_precharge_bank) begin for (i=0; i<`BANKS; i=i+1) begin // Write with Auto Precharge Calculation // 1. Meet minimum tRAS requirement // 2. Write Latency PLUS BL/2 cycles PLUS WR after Write command if (write_precharge_bank[i]) begin if ($time - tm_bank_activate[i] >= TRAS_MIN) begin if (ck_cntr - ck_bank_write[i] >= write_latency + burst_length/2 + write_recovery) begin if (DEBUG) $display ("%m: at time %t INFO: Auto Precharge bank %d", $time, i); write_precharge_bank[i] = 0; active_bank[i] = 0; auto_precharge_bank[i] = 0; tm_bank_precharge[i] = $time; tm_precharge = $time; ck_precharge = ck_cntr; end end end // Read with Auto Precharge Calculation // 1. Meet minimum tRAS requirement // 2. Additive Latency plus 4 cycles after Read command // 3. tRTP after the last 8-bit prefetch if (read_precharge_bank[i]) begin if (($time - tm_bank_activate[i] >= TRAS_MIN) && (ck_cntr - ck_bank_read[i] >= additive_latency + TRTP_TCK)) begin read_precharge_bank[i] = 0; // In case the internal precharge is pushed out by tRTP, tRP starts at the point where // the internal precharge happens (not at the next rising clock edge after this event). if ($time - tm_bank_read_end[i] < TRTP) begin if (DEBUG) $display ("%m: at time %t INFO: Auto Precharge bank %d", tm_bank_read_end[i] + TRTP, i); active_bank[i] <= #(tm_bank_read_end[i] + TRTP - $time) 0; auto_precharge_bank[i] <= #(tm_bank_read_end[i] + TRTP - $time) 0; tm_bank_precharge[i] <= #(tm_bank_read_end[i] + TRTP - $time) tm_bank_read_end[i] + TRTP; tm_precharge <= #(tm_bank_read_end[i] + TRTP - $time) tm_bank_read_end[i] + TRTP; ck_precharge = ck_cntr; end else begin if (DEBUG) $display ("%m: at time %t INFO: Auto Precharge bank %d", $time, i); active_bank[i] = 0; auto_precharge_bank[i] = 0; tm_bank_precharge[i] = $time; tm_precharge = $time; ck_precharge = ck_cntr; end end end end end // respond to incoming command if (cke_in ^ prev_cke) begin tm_cke_cmd <= $time; ck_cke_cmd <= ck_cntr; end cmd_task(cke_in, cmd_n_in, ba_in, addr_in); if ((cmd_n_in == WRITE) || (cmd_n_in == READ)) begin al_pipeline[2*additive_latency] = 1'b1; end if (al_pipeline[0]) begin // check tRCD after additive latency if ((rd_pipeline[2*cas_latency - 1]) && ($time - tm_bank_activate[ba_pipeline[2*cas_latency - 1]] < TRCD)) $display ("%m: at time %t ERROR: tRCD violation during %s", $time, cmd_string[READ]); if ((wr_pipeline[2*cas_write_latency + 1]) && ($time - tm_bank_activate[ba_pipeline[2*cas_write_latency + 1]] < TRCD)) $display ("%m: at time %t ERROR: tRCD violation during %s", $time, cmd_string[WRITE]); // check tWTR after additive latency if (rd_pipeline[2*cas_latency - 1]) begin //{ if (truebl4) begin //{ i = ba_pipeline[2*cas_latency - 1]; if ($time - tm_group_write_end[i[1]] < TWTR) $display ("%m: at time %t ERROR: tWTR violation during %s", $time, cmd_string[READ]); if ($time - tm_write_end < TWTR_DG) $display ("%m: at time %t ERROR: tWTR_DG violation during %s", $time, cmd_string[READ]); end else begin if ($time - tm_write_end < TWTR) $display ("%m: at time %t ERROR: tWTR violation during %s", $time, cmd_string[READ]); end end end if (rd_pipeline) begin if (rd_pipeline[2*cas_latency - 1]) begin tm_bank_read_end[ba_pipeline[2*cas_latency - 1]] <= $time; end end for (i=0; i<`BANKS; i=i+1) begin if ((ck_cntr - ck_bank_write[i] > write_latency) && (ck_cntr - ck_bank_write[i] <= write_latency + burst_length/2)) begin tm_bank_write_end[i] <= $time; tm_group_write_end[i[1]] <= $time; tm_write_end <= $time; end end // clk pin is disabled during self refresh if (!in_self_refresh && tm_ck_pos ) begin tjit_cc_time = $time - tm_ck_pos - tck_i; tck_i = $time - tm_ck_pos; tck_avg = tck_avg - tck_sample[ck_cntr%TDLLK]/$itor(TDLLK); tck_avg = tck_avg + tck_i/$itor(TDLLK); tck_sample[ck_cntr%TDLLK] = tck_i; tjit_per_rtime = tck_i - tck_avg; if (dll_locked && check_strict_timing) begin // check accumulated error terr_nper_rtime = 0; for (i=0; i<12; i=i+1) begin terr_nper_rtime = terr_nper_rtime + tck_sample[i] - tck_avg; terr_nper_rtime = abs_value(terr_nper_rtime); case (i) 0 :; 1 : if (terr_nper_rtime - TERR_2PER >= 1.0) $display ("%m: at time %t ERROR: tERR(2per) violation by %f ps.", $time, terr_nper_rtime - TERR_2PER); 2 : if (terr_nper_rtime - TERR_3PER >= 1.0) $display ("%m: at time %t ERROR: tERR(3per) violation by %f ps.", $time, terr_nper_rtime - TERR_3PER); 3 : if (terr_nper_rtime - TERR_4PER >= 1.0) $display ("%m: at time %t ERROR: tERR(4per) violation by %f ps.", $time, terr_nper_rtime - TERR_4PER); 4 : if (terr_nper_rtime - TERR_5PER >= 1.0) $display ("%m: at time %t ERROR: tERR(5per) violation by %f ps.", $time, terr_nper_rtime - TERR_5PER); 5 : if (terr_nper_rtime - TERR_6PER >= 1.0) $display ("%m: at time %t ERROR: tERR(6per) violation by %f ps.", $time, terr_nper_rtime - TERR_6PER); 6 : if (terr_nper_rtime - TERR_7PER >= 1.0) $display ("%m: at time %t ERROR: tERR(7per) violation by %f ps.", $time, terr_nper_rtime - TERR_7PER); 7 : if (terr_nper_rtime - TERR_8PER >= 1.0) $display ("%m: at time %t ERROR: tERR(8per) violation by %f ps.", $time, terr_nper_rtime - TERR_8PER); 8 : if (terr_nper_rtime - TERR_9PER >= 1.0) $display ("%m: at time %t ERROR: tERR(9per) violation by %f ps.", $time, terr_nper_rtime - TERR_9PER); 9 : if (terr_nper_rtime - TERR_10PER >= 1.0) $display ("%m: at time %t ERROR: tERR(10per) violation by %f ps.", $time, terr_nper_rtime - TERR_10PER); 10 : if (terr_nper_rtime - TERR_11PER >= 1.0) $display ("%m: at time %t ERROR: tERR(11per) violation by %f ps.", $time, terr_nper_rtime - TERR_11PER); 11 : if (terr_nper_rtime - TERR_12PER >= 1.0) $display ("%m: at time %t ERROR: tERR(12per) violation by %f ps.", $time, terr_nper_rtime - TERR_12PER); endcase end // check tCK min/max/jitter if (abs_value(tjit_per_rtime) - TJIT_PER >= 1.0) $display ("%m: at time %t ERROR: tJIT(per) violation by %f ps.", $time, abs_value(tjit_per_rtime) - TJIT_PER); if (abs_value(tjit_cc_time) - TJIT_CC >= 1.0) $display ("%m: at time %t ERROR: tJIT(cc) violation by %f ps.", $time, abs_value(tjit_cc_time) - TJIT_CC); if (TCK_MIN - tck_avg >= 1.0) $display ("%m: at time %t ERROR: tCK(avg) minimum violation by %f ps.", $time, TCK_MIN - tck_avg); if (tck_avg - TCK_MAX >= 1.0) $display ("%m: at time %t ERROR: tCK(avg) maximum violation by %f ps.", $time, tck_avg - TCK_MAX); // check tCL if (tm_ck_neg - $time < TCL_ABS_MIN*tck_avg) $display ("%m: at time %t ERROR: tCL(abs) minimum violation on CLK by %t", $time, TCL_ABS_MIN*tck_avg - tm_ck_neg + $time); if (tcl_avg < TCL_AVG_MIN*tck_avg) $display ("%m: at time %t ERROR: tCL(avg) minimum violation on CLK by %t", $time, TCL_AVG_MIN*tck_avg - tcl_avg); if (tcl_avg > TCL_AVG_MAX*tck_avg) $display ("%m: at time %t ERROR: tCL(avg) maximum violation on CLK by %t", $time, tcl_avg - TCL_AVG_MAX*tck_avg); end // calculate the tch avg jitter tch_avg = tch_avg - tch_sample[ck_cntr%TDLLK]/$itor(TDLLK); tch_avg = tch_avg + tch_i/$itor(TDLLK); tch_sample[ck_cntr%TDLLK] = tch_i; tjit_ch_rtime = tch_i - tch_avg; duty_cycle = tch_avg/tck_avg; // update timers/counters tcl_i <= $time - tm_ck_neg; end prev_odt <= odt_in; // update timers/counters ck_cntr <= ck_cntr + 1; tm_ck_pos = $time; end else begin // clk pin is disabled during self refresh if (!in_self_refresh) begin if (dll_locked && check_strict_timing) begin if ($time - tm_ck_pos < TCH_ABS_MIN*tck_avg) $display ("%m: at time %t ERROR: tCH(abs) minimum violation on CLK by %t", $time, TCH_ABS_MIN*tck_avg - $time + tm_ck_pos); if (tch_avg < TCH_AVG_MIN*tck_avg) $display ("%m: at time %t ERROR: tCH(avg) minimum violation on CLK by %t", $time, TCH_AVG_MIN*tck_avg - tch_avg); if (tch_avg > TCH_AVG_MAX*tck_avg) $display ("%m: at time %t ERROR: tCH(avg) maximum violation on CLK by %t", $time, tch_avg - TCH_AVG_MAX*tck_avg); end // calculate the tcl avg jitter tcl_avg = tcl_avg - tcl_sample[ck_cntr%TDLLK]/$itor(TDLLK); tcl_avg = tcl_avg + tcl_i/$itor(TDLLK); tcl_sample[ck_cntr%TDLLK] = tcl_i; // update timers/counters tch_i <= $time - tm_ck_pos; end tm_ck_neg = $time; end // on die termination if (odt_en || dyn_odt_en) begin // odt pin is disabled during self refresh if (!in_self_refresh && diff_ck) begin if ($time - tm_odt < TIS) $display ("%m: at time %t ERROR: tIS violation on ODT by %t", $time, tm_odt + TIS - $time); if (prev_odt ^ odt_in) begin if (!dll_locked) $display ("%m: at time %t WARNING: tDLLK violation during ODT transition.", $time); if (($time - tm_load_mode < TMOD) || (ck_cntr - ck_load_mode < TMOD_TCK)) $display ("%m: at time %t ERROR: tMOD violation during ODT transition", $time); if (ck_cntr - ck_zqinit < TZQINIT) $display ("%m: at time %t ERROR: TZQinit violation during ODT transition", $time); if (ck_cntr - ck_zqoper < TZQOPER) $display ("%m: at time %t ERROR: TZQoper violation during ODT transition", $time); if (ck_cntr - ck_zqcs < TZQCS) $display ("%m: at time %t ERROR: tZQcs violation during ODT transition", $time); // if (($time - tm_slow_exit_pd < TXPDLL) || (ck_cntr - ck_slow_exit_pd < TXPDLL_TCK)) // $display ("%m: at time %t ERROR: tXPDLL violation during ODT transition", $time); if (ck_cntr - ck_self_refresh < TXSDLL) $display ("%m: at time %t ERROR: tXSDLL violation during ODT transition", $time); if (in_self_refresh) $display ("%m: at time %t ERROR: Illegal ODT transition during Self Refresh.", $time); if (!odt_in && (ck_cntr - ck_odt < ODTH4)) $display ("%m: at time %t ERROR: ODTH4 violation during ODT transition", $time); if (!odt_in && (ck_cntr - ck_odth8 < ODTH8)) $display ("%m: at time %t ERROR: ODTH8 violation during ODT transition", $time); if (($time - tm_slow_exit_pd < TXPDLL) || (ck_cntr - ck_slow_exit_pd < TXPDLL_TCK)) $display ("%m: at time %t WARNING: tXPDLL during ODT transition. Synchronous or asynchronous change in termination resistance is possible.", $time); // async ODT mode applies: // 1.) during precharge power down with DLL off // 2.) if tANPD has not been satisfied // 3.) until tXPDLL has been satisfied if ((in_power_down && low_power && (active_bank == 0)) || ($time - tm_slow_exit_pd < TXPDLL) || (ck_cntr - ck_slow_exit_pd < TXPDLL_TCK)) begin odt_state = odt_in; if (DEBUG && odt_en) $display ("%m: at time %t INFO: Async On Die Termination Rtt_NOM = %d Ohm", $time, {32{odt_state}} & get_rtt_nom(odt_rtt_nom)); if (odt_state) begin odt_state_dly <= #(TAONPD) odt_state; end else begin odt_state_dly <= #(TAOFPD) odt_state; end // sync ODT mode applies: // 1.) during normal operation // 2.) during active power down // 3.) during precharge power down with DLL on end else begin odt_pipeline[2*(write_latency - 2)] = 1'b1; // ODTLon, ODTLoff end ck_odt <= ck_cntr; end end if (odt_pipeline[0]) begin odt_state = ~odt_state; if (DEBUG && odt_en) $display ("%m: at time %t INFO: Sync On Die Termination Rtt_NOM = %d Ohm", $time, {32{odt_state}} & get_rtt_nom(odt_rtt_nom)); if (odt_state) begin odt_state_dly <= #(TAON) odt_state; end else begin odt_state_dly <= #(TAOF*tck_avg) odt_state; end end if (rd_pipeline[RDQSEN_PRE]) begin odt_cntr = 1 + RDQSEN_PRE + bl_pipeline[RDQSEN_PRE] + RDQSEN_PST - 1; end if (odt_cntr > 0) begin if (odt_state) begin $display ("%m: at time %t ERROR: On Die Termination must be OFF during Read data transfer.", $time); end odt_cntr = odt_cntr - 1; end if (dyn_odt_en && odt_state) begin if (DEBUG && (dyn_odt_state ^ dyn_odt_pipeline[0])) $display ("%m: at time %t INFO: Sync On Die Termination Rtt_WR = %d Ohm", $time, {32{dyn_odt_pipeline[0]}} & get_rtt_wr(odt_rtt_wr)); dyn_odt_state = dyn_odt_pipeline[0]; end dyn_odt_state_dly <= #(TADC*tck_avg) dyn_odt_state; end if (cke_in && write_levelization) begin for (i=0; i<DQS_BITS; i=i+1) begin if ($time - tm_dqs_pos[i] < TWLH) $display ("%m: at time %t WARNING: tWLH violation on DQS bit %d positive edge. Indeterminate CK capture is possible.", $time, i); end end // shift pipelines if (|wr_pipeline || |rd_pipeline || |al_pipeline) begin al_pipeline = al_pipeline>>1; wr_pipeline = wr_pipeline>>1; rd_pipeline = rd_pipeline>>1; for (i=0; i<`MAX_PIPE; i=i+1) begin bl_pipeline[i] = bl_pipeline[i+1]; ba_pipeline[i] = ba_pipeline[i+1]; row_pipeline[i] = row_pipeline[i+1]; col_pipeline[i] = col_pipeline[i+1]; end end if (|odt_pipeline || |dyn_odt_pipeline) begin odt_pipeline = odt_pipeline>>1; dyn_odt_pipeline = dyn_odt_pipeline>>1; end end end // receiver(s) task dqs_even_receiver; input [3:0] i; reg [63:0] bit_mask; begin bit_mask = {`DQ_PER_DQS{1'b1}}<<(i*`DQ_PER_DQS); if (dqs_even[i]) begin if (tdqs_en) begin // tdqs disables dm dm_in_pos[i] = 1'b0; end else begin dm_in_pos[i] = dm_in[i]; end dq_in_pos = (dq_in & bit_mask) | (dq_in_pos & ~bit_mask); end end endtask always @(posedge dqs_even[ 0]) dqs_even_receiver( 0); always @(posedge dqs_even[ 1]) dqs_even_receiver( 1); always @(posedge dqs_even[ 2]) dqs_even_receiver( 2); always @(posedge dqs_even[ 3]) dqs_even_receiver( 3); always @(posedge dqs_even[ 4]) dqs_even_receiver( 4); always @(posedge dqs_even[ 5]) dqs_even_receiver( 5); always @(posedge dqs_even[ 6]) dqs_even_receiver( 6); always @(posedge dqs_even[ 7]) dqs_even_receiver( 7); always @(posedge dqs_even[ 8]) dqs_even_receiver( 8); always @(posedge dqs_even[ 9]) dqs_even_receiver( 9); always @(posedge dqs_even[10]) dqs_even_receiver(10); always @(posedge dqs_even[11]) dqs_even_receiver(11); always @(posedge dqs_even[12]) dqs_even_receiver(12); always @(posedge dqs_even[13]) dqs_even_receiver(13); always @(posedge dqs_even[14]) dqs_even_receiver(14); always @(posedge dqs_even[15]) dqs_even_receiver(15); task dqs_odd_receiver; input [3:0] i; reg [63:0] bit_mask; begin bit_mask = {`DQ_PER_DQS{1'b1}}<<(i*`DQ_PER_DQS); if (dqs_odd[i]) begin if (tdqs_en) begin // tdqs disables dm dm_in_neg[i] = 1'b0; end else begin dm_in_neg[i] = dm_in[i]; end dq_in_neg = (dq_in & bit_mask) | (dq_in_neg & ~bit_mask); end end endtask always @(posedge dqs_odd[ 0]) dqs_odd_receiver( 0); always @(posedge dqs_odd[ 1]) dqs_odd_receiver( 1); always @(posedge dqs_odd[ 2]) dqs_odd_receiver( 2); always @(posedge dqs_odd[ 3]) dqs_odd_receiver( 3); always @(posedge dqs_odd[ 4]) dqs_odd_receiver( 4); always @(posedge dqs_odd[ 5]) dqs_odd_receiver( 5); always @(posedge dqs_odd[ 6]) dqs_odd_receiver( 6); always @(posedge dqs_odd[ 7]) dqs_odd_receiver( 7); always @(posedge dqs_odd[ 8]) dqs_odd_receiver( 8); always @(posedge dqs_odd[ 9]) dqs_odd_receiver( 9); always @(posedge dqs_odd[10]) dqs_odd_receiver(10); always @(posedge dqs_odd[11]) dqs_odd_receiver(11); always @(posedge dqs_odd[12]) dqs_odd_receiver(12); always @(posedge dqs_odd[13]) dqs_odd_receiver(13); always @(posedge dqs_odd[14]) dqs_odd_receiver(14); always @(posedge dqs_odd[15]) dqs_odd_receiver(15); // Processes to check hold and pulse width of control signals always @(posedge rst_n_in) begin if ($time > 100000) begin if (tm_rst_n + 100000 > $time) $display ("%m: at time %t ERROR: RST_N pulse width violation by %t", $time, tm_rst_n + 100000 - $time); end tm_rst_n = $time; end always @(cke_in) begin if (rst_n_in) begin if ($time > TIH) begin if ($time - tm_ck_pos < TIH) $display ("%m: at time %t ERROR: tIH violation on CKE by %t", $time, tm_ck_pos + TIH - $time); end if ($time - tm_cke < TIPW) $display ("%m: at time %t ERROR: tIPW violation on CKE by %t", $time, tm_cke + TIPW - $time); end tm_cke = $time; end always @(odt_in) begin if (rst_n_in && odt_en && !in_self_refresh) begin if ($time - tm_ck_pos < TIH) $display ("%m: at time %t ERROR: tIH violation on ODT by %t", $time, tm_ck_pos + TIH - $time); if ($time - tm_odt < TIPW) $display ("%m: at time %t ERROR: tIPW violation on ODT by %t", $time, tm_odt + TIPW - $time); end tm_odt = $time; end task cmd_addr_timing_check; input i; reg [4:0] i; begin if (rst_n_in && prev_cke) begin if ((i == 0) && ($time - tm_ck_pos < TIH)) // always check tIH for CS# $display ("%m: at time %t ERROR: tIH violation on %s by %t", $time, cmd_addr_string[i], tm_ck_pos + TIH - $time); if ((i > 0) && (cs_n_in == 0) &&($time - tm_ck_pos < TIH)) // Only check tIH for cmd_addr if CS# is low $display ("%m: at time %t ERROR: tIH violation on %s by %t", $time, cmd_addr_string[i], tm_ck_pos + TIH - $time); if ($time - tm_cmd_addr[i] < TIPW) $display ("%m: at time %t ERROR: tIPW violation on %s by %t", $time, cmd_addr_string[i], tm_cmd_addr[i] + TIPW - $time); end tm_cmd_addr[i] = $time; end endtask always @(cs_n_in ) cmd_addr_timing_check( 0); always @(ras_n_in ) cmd_addr_timing_check( 1); always @(cas_n_in ) cmd_addr_timing_check( 2); always @(we_n_in ) cmd_addr_timing_check( 3); always @(ba_in [ 0]) cmd_addr_timing_check( 4); always @(ba_in [ 1]) cmd_addr_timing_check( 5); always @(ba_in [ 2]) cmd_addr_timing_check( 6); always @(addr_in[ 0]) cmd_addr_timing_check( 7); always @(addr_in[ 1]) cmd_addr_timing_check( 8); always @(addr_in[ 2]) cmd_addr_timing_check( 9); always @(addr_in[ 3]) cmd_addr_timing_check(10); always @(addr_in[ 4]) cmd_addr_timing_check(11); always @(addr_in[ 5]) cmd_addr_timing_check(12); always @(addr_in[ 6]) cmd_addr_timing_check(13); always @(addr_in[ 7]) cmd_addr_timing_check(14); always @(addr_in[ 8]) cmd_addr_timing_check(15); always @(addr_in[ 9]) cmd_addr_timing_check(16); always @(addr_in[10]) cmd_addr_timing_check(17); always @(addr_in[11]) cmd_addr_timing_check(18); always @(addr_in[12]) cmd_addr_timing_check(19); always @(addr_in[13]) cmd_addr_timing_check(20); always @(addr_in[14]) cmd_addr_timing_check(21); always @(addr_in[15]) cmd_addr_timing_check(22); // Processes to check setup and hold of data signals task dm_timing_check; input i; reg [3:0] i; begin if (dqs_in_valid) begin if ($time - tm_dqs[i] < TDH) $display ("%m: at time %t ERROR: tDH violation on DM bit %d by %t", $time, i, tm_dqs[i] + TDH - $time); if (check_dm_tdipw[i]) begin if ($time - tm_dm[i] < TDIPW) $display ("%m: at time %t ERROR: tDIPW violation on DM bit %d by %t", $time, i, tm_dm[i] + TDIPW - $time); end end check_dm_tdipw[i] <= 1'b0; tm_dm[i] = $time; end endtask always @(dm_in[ 0]) dm_timing_check( 0); always @(dm_in[ 1]) dm_timing_check( 1); always @(dm_in[ 2]) dm_timing_check( 2); always @(dm_in[ 3]) dm_timing_check( 3); always @(dm_in[ 4]) dm_timing_check( 4); always @(dm_in[ 5]) dm_timing_check( 5); always @(dm_in[ 6]) dm_timing_check( 6); always @(dm_in[ 7]) dm_timing_check( 7); always @(dm_in[ 8]) dm_timing_check( 8); always @(dm_in[ 9]) dm_timing_check( 9); always @(dm_in[10]) dm_timing_check(10); always @(dm_in[11]) dm_timing_check(11); always @(dm_in[12]) dm_timing_check(12); always @(dm_in[13]) dm_timing_check(13); always @(dm_in[14]) dm_timing_check(14); always @(dm_in[15]) dm_timing_check(15); task dq_timing_check; input i; reg [5:0] i; begin if (dqs_in_valid) begin if ($time - tm_dqs[i/`DQ_PER_DQS] < TDH) $display ("%m: at time %t ERROR: tDH violation on DQ bit %d by %t", $time, i, tm_dqs[i/`DQ_PER_DQS] + TDH - $time); if (check_dq_tdipw[i]) begin if ($time - tm_dq[i] < TDIPW) $display ("%m: at time %t ERROR: tDIPW violation on DQ bit %d by %t", $time, i, tm_dq[i] + TDIPW - $time); end end check_dq_tdipw[i] <= 1'b0; tm_dq[i] = $time; end endtask always @(dq_in[ 0]) dq_timing_check( 0); always @(dq_in[ 1]) dq_timing_check( 1); always @(dq_in[ 2]) dq_timing_check( 2); always @(dq_in[ 3]) dq_timing_check( 3); always @(dq_in[ 4]) dq_timing_check( 4); always @(dq_in[ 5]) dq_timing_check( 5); always @(dq_in[ 6]) dq_timing_check( 6); always @(dq_in[ 7]) dq_timing_check( 7); always @(dq_in[ 8]) dq_timing_check( 8); always @(dq_in[ 9]) dq_timing_check( 9); always @(dq_in[10]) dq_timing_check(10); always @(dq_in[11]) dq_timing_check(11); always @(dq_in[12]) dq_timing_check(12); always @(dq_in[13]) dq_timing_check(13); always @(dq_in[14]) dq_timing_check(14); always @(dq_in[15]) dq_timing_check(15); always @(dq_in[16]) dq_timing_check(16); always @(dq_in[17]) dq_timing_check(17); always @(dq_in[18]) dq_timing_check(18); always @(dq_in[19]) dq_timing_check(19); always @(dq_in[20]) dq_timing_check(20); always @(dq_in[21]) dq_timing_check(21); always @(dq_in[22]) dq_timing_check(22); always @(dq_in[23]) dq_timing_check(23); always @(dq_in[24]) dq_timing_check(24); always @(dq_in[25]) dq_timing_check(25); always @(dq_in[26]) dq_timing_check(26); always @(dq_in[27]) dq_timing_check(27); always @(dq_in[28]) dq_timing_check(28); always @(dq_in[29]) dq_timing_check(29); always @(dq_in[30]) dq_timing_check(30); always @(dq_in[31]) dq_timing_check(31); always @(dq_in[32]) dq_timing_check(32); always @(dq_in[33]) dq_timing_check(33); always @(dq_in[34]) dq_timing_check(34); always @(dq_in[35]) dq_timing_check(35); always @(dq_in[36]) dq_timing_check(36); always @(dq_in[37]) dq_timing_check(37); always @(dq_in[38]) dq_timing_check(38); always @(dq_in[39]) dq_timing_check(39); always @(dq_in[40]) dq_timing_check(40); always @(dq_in[41]) dq_timing_check(41); always @(dq_in[42]) dq_timing_check(42); always @(dq_in[43]) dq_timing_check(43); always @(dq_in[44]) dq_timing_check(44); always @(dq_in[45]) dq_timing_check(45); always @(dq_in[46]) dq_timing_check(46); always @(dq_in[47]) dq_timing_check(47); always @(dq_in[48]) dq_timing_check(48); always @(dq_in[49]) dq_timing_check(49); always @(dq_in[50]) dq_timing_check(50); always @(dq_in[51]) dq_timing_check(51); always @(dq_in[52]) dq_timing_check(52); always @(dq_in[53]) dq_timing_check(53); always @(dq_in[54]) dq_timing_check(54); always @(dq_in[55]) dq_timing_check(55); always @(dq_in[56]) dq_timing_check(56); always @(dq_in[57]) dq_timing_check(57); always @(dq_in[58]) dq_timing_check(58); always @(dq_in[59]) dq_timing_check(59); always @(dq_in[60]) dq_timing_check(60); always @(dq_in[61]) dq_timing_check(61); always @(dq_in[62]) dq_timing_check(62); always @(dq_in[63]) dq_timing_check(63); task dqs_pos_timing_check; input i; reg [4:0] i; reg [3:0] j; begin if (write_levelization && i<16) begin if (ck_cntr - ck_load_mode < TWLMRD) $display ("%m: at time %t ERROR: tWLMRD violation on DQS bit %d positive edge.", $time, i); if (($time - tm_ck_pos < TWLS) || ($time - tm_ck_neg < TWLS)) $display ("%m: at time %t WARNING: tWLS violation on DQS bit %d positive edge. Indeterminate CK capture is possible.", $time, i); if (DEBUG) $display ("%m: at time %t Write Leveling @ DQS ck = %b", $time, diff_ck); dq_out_en_dly[i*`DQ_PER_DQS] <= #(TWLO) 1'b1; dq_out_dly[i*`DQ_PER_DQS] <= #(TWLO) diff_ck; for (j=1; j<`DQ_PER_DQS; j=j+1) begin dq_out_en_dly[i*`DQ_PER_DQS+j] <= #(TWLO + TWLOE) 1'b1; dq_out_dly[i*`DQ_PER_DQS+j] <= #(TWLO + TWLOE) 1'b0; end end if (dqs_in_valid && ((wdqs_pos_cntr[i] < wr_burst_length/2) || b2b_write)) begin if (dqs_in[i] ^ prev_dqs_in[i]) begin if (dll_locked) begin if (check_write_preamble[i]) begin if ($time - tm_dqs_pos[i] < $rtoi(TWPRE*tck_avg)) $display ("%m: at time %t ERROR: tWPRE violation on &s bit %d", $time, dqs_string[i/16], i%16); end else if (check_write_postamble[i]) begin if ($time - tm_dqs_neg[i] < $rtoi(TWPST*tck_avg)) $display ("%m: at time %t ERROR: tWPST violation on %s bit %d", $time, dqs_string[i/16], i%16); end else begin if ($time - tm_dqs_neg[i] < $rtoi(TDQSL*tck_avg)) $display ("%m: at time %t ERROR: tDQSL violation on %s bit %d", $time, dqs_string[i/16], i%16); end end if ($time - tm_dm[i%16] < TDS) $display ("%m: at time %t ERROR: tDS violation on DM bit %d by %t", $time, i, tm_dm[i%16] + TDS - $time); if (!dq_out_en) begin for (j=0; j<`DQ_PER_DQS; j=j+1) begin if ($time - tm_dq[(i%16)*`DQ_PER_DQS+j] < TDS) $display ("%m: at time %t ERROR: tDS violation on DQ bit %d by %t", $time, i*`DQ_PER_DQS+j, tm_dq[(i%16)*`DQ_PER_DQS+j] + TDS - $time); check_dq_tdipw[(i%16)*`DQ_PER_DQS+j] <= 1'b1; end end if ((wdqs_pos_cntr[i] < wr_burst_length/2) && !b2b_write) begin wdqs_pos_cntr[i] <= wdqs_pos_cntr[i] + 1; end else begin wdqs_pos_cntr[i] <= 1; end check_dm_tdipw[i%16] <= 1'b1; check_write_preamble[i] <= 1'b0; check_write_postamble[i] <= 1'b0; check_write_dqs_low[i] <= 1'b0; tm_dqs[i%16] <= $time; end else begin $display ("%m: at time %t ERROR: Invalid latching edge on %s bit %d", $time, dqs_string[i/16], i%16); end end tm_dqss_pos[i] <= $time; tm_dqs_pos[i] = $time; prev_dqs_in[i] <= dqs_in[i]; end endtask always @(posedge dqs_in[ 0]) dqs_pos_timing_check( 0); always @(posedge dqs_in[ 1]) dqs_pos_timing_check( 1); always @(posedge dqs_in[ 2]) dqs_pos_timing_check( 2); always @(posedge dqs_in[ 3]) dqs_pos_timing_check( 3); always @(posedge dqs_in[ 4]) dqs_pos_timing_check( 4); always @(posedge dqs_in[ 5]) dqs_pos_timing_check( 5); always @(posedge dqs_in[ 6]) dqs_pos_timing_check( 6); always @(posedge dqs_in[ 7]) dqs_pos_timing_check( 7); always @(posedge dqs_in[ 8]) dqs_pos_timing_check( 8); always @(posedge dqs_in[ 9]) dqs_pos_timing_check( 9); always @(posedge dqs_in[10]) dqs_pos_timing_check(10); always @(posedge dqs_in[11]) dqs_pos_timing_check(11); always @(posedge dqs_in[12]) dqs_pos_timing_check(12); always @(posedge dqs_in[13]) dqs_pos_timing_check(13); always @(posedge dqs_in[14]) dqs_pos_timing_check(14); always @(posedge dqs_in[15]) dqs_pos_timing_check(15); always @(negedge dqs_in[16]) dqs_pos_timing_check(16); always @(negedge dqs_in[17]) dqs_pos_timing_check(17); always @(negedge dqs_in[18]) dqs_pos_timing_check(18); always @(negedge dqs_in[19]) dqs_pos_timing_check(19); always @(negedge dqs_in[20]) dqs_pos_timing_check(20); always @(negedge dqs_in[21]) dqs_pos_timing_check(21); always @(negedge dqs_in[22]) dqs_pos_timing_check(22); always @(negedge dqs_in[23]) dqs_pos_timing_check(23); always @(negedge dqs_in[24]) dqs_pos_timing_check(24); always @(negedge dqs_in[25]) dqs_pos_timing_check(25); always @(negedge dqs_in[26]) dqs_pos_timing_check(26); always @(negedge dqs_in[27]) dqs_pos_timing_check(27); always @(negedge dqs_in[28]) dqs_pos_timing_check(28); always @(negedge dqs_in[29]) dqs_pos_timing_check(29); always @(negedge dqs_in[30]) dqs_pos_timing_check(30); always @(negedge dqs_in[31]) dqs_pos_timing_check(31); task dqs_neg_timing_check; input i; reg [4:0] i; reg [3:0] j; begin if (write_levelization && i<16) begin if (ck_cntr - ck_load_mode < TWLDQSEN) $display ("%m: at time %t ERROR: tWLDQSEN violation on DQS bit %d.", $time, i); if ($time - tm_dqs_pos[i] < $rtoi(TDQSH*tck_avg)) $display ("%m: at time %t ERROR: tDQSH violation on DQS bit %d by %t", $time, i, tm_dqs_pos[i] + TDQSH*tck_avg - $time); end if (dqs_in_valid && (wdqs_pos_cntr[i] > 0) && check_write_dqs_high[i]) begin if (dqs_in[i] ^ prev_dqs_in[i]) begin if (dll_locked) begin if ($time - tm_dqs_pos[i] < $rtoi(TDQSH*tck_avg)) $display ("%m: at time %t ERROR: tDQSH violation on %s bit %d", $time, dqs_string[i/16], i%16); if ($time - tm_ck_pos < $rtoi(TDSH*tck_avg)) $display ("%m: at time %t ERROR: tDSH violation on %s bit %d", $time, dqs_string[i/16], i%16); end if ($time - tm_dm[i%16] < TDS) $display ("%m: at time %t ERROR: tDS violation on DM bit %d by %t", $time, i, tm_dm[i%16] + TDS - $time); if (!dq_out_en) begin for (j=0; j<`DQ_PER_DQS; j=j+1) begin if ($time - tm_dq[(i%16)*`DQ_PER_DQS+j] < TDS) $display ("%m: at time %t ERROR: tDS violation on DQ bit %d by %t", $time, i*`DQ_PER_DQS+j, tm_dq[(i%16)*`DQ_PER_DQS+j] + TDS - $time); check_dq_tdipw[(i%16)*`DQ_PER_DQS+j] <= 1'b1; end end check_dm_tdipw[i%16] <= 1'b1; tm_dqs[i%16] <= $time; end else begin $display ("%m: at time %t ERROR: Invalid latching edge on %s bit %d", $time, dqs_string[i/16], i%16); end end check_write_dqs_high[i] <= 1'b0; tm_dqs_neg[i] = $time; prev_dqs_in[i] <= dqs_in[i]; end endtask always @(negedge dqs_in[ 0]) dqs_neg_timing_check( 0); always @(negedge dqs_in[ 1]) dqs_neg_timing_check( 1); always @(negedge dqs_in[ 2]) dqs_neg_timing_check( 2); always @(negedge dqs_in[ 3]) dqs_neg_timing_check( 3); always @(negedge dqs_in[ 4]) dqs_neg_timing_check( 4); always @(negedge dqs_in[ 5]) dqs_neg_timing_check( 5); always @(negedge dqs_in[ 6]) dqs_neg_timing_check( 6); always @(negedge dqs_in[ 7]) dqs_neg_timing_check( 7); always @(negedge dqs_in[ 8]) dqs_neg_timing_check( 8); always @(negedge dqs_in[ 9]) dqs_neg_timing_check( 9); always @(negedge dqs_in[10]) dqs_neg_timing_check(10); always @(negedge dqs_in[11]) dqs_neg_timing_check(11); always @(negedge dqs_in[12]) dqs_neg_timing_check(12); always @(negedge dqs_in[13]) dqs_neg_timing_check(13); always @(negedge dqs_in[14]) dqs_neg_timing_check(14); always @(negedge dqs_in[15]) dqs_neg_timing_check(15); always @(posedge dqs_in[16]) dqs_neg_timing_check(16); always @(posedge dqs_in[17]) dqs_neg_timing_check(17); always @(posedge dqs_in[18]) dqs_neg_timing_check(18); always @(posedge dqs_in[19]) dqs_neg_timing_check(19); always @(posedge dqs_in[20]) dqs_neg_timing_check(20); always @(posedge dqs_in[21]) dqs_neg_timing_check(21); always @(posedge dqs_in[22]) dqs_neg_timing_check(22); always @(posedge dqs_in[23]) dqs_neg_timing_check(23); always @(posedge dqs_in[24]) dqs_neg_timing_check(24); always @(posedge dqs_in[25]) dqs_neg_timing_check(25); always @(posedge dqs_in[26]) dqs_neg_timing_check(26); always @(posedge dqs_in[27]) dqs_neg_timing_check(27); always @(posedge dqs_in[28]) dqs_neg_timing_check(28); always @(posedge dqs_in[29]) dqs_neg_timing_check(29); always @(posedge dqs_in[30]) dqs_neg_timing_check(30); always @(posedge dqs_in[31]) dqs_neg_timing_check(31); endmodule
/**************************************************************************************** * * File Name: ddr3.v * Version: 1.61 * Model: BUS Functional * * Dependencies: ddr3_model_parameters_c3.vh * * Description: Micron SDRAM DDR3 (Double Data Rate 3) * * Limitation: - doesn't check for average refresh timings * - positive ck and ck_n edges are used to form internal clock * - positive dqs and dqs_n edges are used to latch data * - test mode is not modeled * - Duty Cycle Corrector is not modeled * - Temperature Compensated Self Refresh is not modeled * - DLL off mode is not modeled. * * Note: - Set simulator resolution to "ps" accuracy * - Set DEBUG = 0 to disable $display messages * * Disclaimer This software code and all associated documentation, comments or other * of Warranty: information (collectively "Software") is provided "AS IS" without * warranty of any kind. MICRON TECHNOLOGY, INC. ("MTI") EXPRESSLY * DISCLAIMS ALL WARRANTIES EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED * TO, NONINFRINGEMENT OF THIRD PARTY RIGHTS, AND ANY IMPLIED WARRANTIES * OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE. MTI DOES NOT * WARRANT THAT THE SOFTWARE WILL MEET YOUR REQUIREMENTS, OR THAT THE * OPERATION OF THE SOFTWARE WILL BE UNINTERRUPTED OR ERROR-FREE. * FURTHERMORE, MTI DOES NOT MAKE ANY REPRESENTATIONS REGARDING THE USE OR * THE RESULTS OF THE USE OF THE SOFTWARE IN TERMS OF ITS CORRECTNESS, * ACCURACY, RELIABILITY, OR OTHERWISE. THE ENTIRE RISK ARISING OUT OF USE * OR PERFORMANCE OF THE SOFTWARE REMAINS WITH YOU. IN NO EVENT SHALL MTI, * ITS AFFILIATED COMPANIES OR THEIR SUPPLIERS BE LIABLE FOR ANY DIRECT, * INDIRECT, CONSEQUENTIAL, INCIDENTAL, OR SPECIAL DAMAGES (INCLUDING, * WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS, BUSINESS INTERRUPTION, * OR LOSS OF INFORMATION) ARISING OUT OF YOUR USE OF OR INABILITY TO USE * THE SOFTWARE, EVEN IF MTI HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH * DAMAGES. Because some jurisdictions prohibit the exclusion or * limitation of liability for consequential or incidental damages, the * above limitation may not apply to you. * * Copyright 2003 Micron Technology, Inc. All rights reserved. * * Rev Author Date Changes * --------------------------------------------------------------------------------------- * 0.41 JMK 05/12/06 Removed auto-precharge to power down error check. * 0.42 JMK 08/25/06 Created internal clock using ck and ck_n. * TDQS can only be enabled in EMR for x8 configurations. * CAS latency is checked vs frequency when DLL locks. * Improved checking of DQS during writes. * Added true BL4 operation. * 0.43 JMK 08/14/06 Added checking for setting reserved bits in Mode Registers. * Added ODTS Readout. * Replaced tZQCL with tZQinit and tZQoper * Fixed tWRPDEN and tWRAPDEN during BC4MRS and BL4MRS. * Added tRFC checking for Refresh to Power-Down Re-Entry. * Added tXPDLL checking for Power-Down Exit to Refresh to Power-Down Entry * Added Clock Frequency Change during Precharge Power-Down. * Added -125x speed grades. * Fixed tRCD checking during Write. * 1.00 JMK 05/11/07 Initial release * 1.10 JMK 06/26/07 Fixed ODTH8 check during BLOTF * Removed temp sensor readout from MPR * Updated initialization sequence * Updated timing parameters * 1.20 JMK 09/05/07 Updated clock frequency change * Added ddr3_dimm module * 1.30 JMK 01/23/08 Updated timing parameters * 1.40 JMK 12/02/08 Added support for DDR3-1866 and DDR3-2133 * renamed ddr3_dimm.v to ddr3_module.v and added SODIMM support. * Added multi-chip package model support in ddr3_mcp.v * 1.50 JMK 05/04/08 Added 1866 and 2133 speed grades. * 1.60 MYY 07/10/09 Merging of 1.50 version and pre-1.0 version changes * 1.61 SPH 12/10/09 Only check tIH for cmd_addr if CS# LOW *****************************************************************************************/ // DO NOT CHANGE THE TIMESCALE // MAKE SURE YOUR SIMULATOR USES "PS" RESOLUTION `timescale 1ps / 1ps // model flags // `define MODEL_PASR module ddr3_model_c3( rst_n, ck, ck_n, cke, cs_n, ras_n, cas_n, we_n, dm_tdqs, ba, addr, dq, dqs, dqs_n, tdqs_n, odt ); `include "ddr3_model_parameters_c3.vh" parameter check_strict_mrbits = 1; parameter check_strict_timing = 1; parameter feature_pasr = 1; parameter feature_truebl4 = 0; // text macros `define DQ_PER_DQS DQ_BITS/DQS_BITS `define BANKS (1<<BA_BITS) `define MAX_BITS (BA_BITS+ROW_BITS+COL_BITS-BL_BITS) `define MAX_SIZE (1<<(BA_BITS+ROW_BITS+COL_BITS-BL_BITS)) `define MEM_SIZE (1<<MEM_BITS) `define MAX_PIPE 4*CL_MAX // Declare Ports input rst_n; input ck; input ck_n; input cke; input cs_n; input ras_n; input cas_n; input we_n; inout [DM_BITS-1:0] dm_tdqs; input [BA_BITS-1:0] ba; input [ADDR_BITS-1:0] addr; inout [DQ_BITS-1:0] dq; inout [DQS_BITS-1:0] dqs; inout [DQS_BITS-1:0] dqs_n; output [DQS_BITS-1:0] tdqs_n; input odt; // clock jitter real tck_avg; time tck_sample [TDLLK-1:0]; time tch_sample [TDLLK-1:0]; time tcl_sample [TDLLK-1:0]; time tck_i; time tch_i; time tcl_i; real tch_avg; real tcl_avg; time tm_ck_pos; time tm_ck_neg; real tjit_per_rtime; integer tjit_cc_time; real terr_nper_rtime; //DDR3 clock jitter variables real tjit_ch_rtime; real duty_cycle; // clock skew real out_delay; integer dqsck [DQS_BITS-1:0]; integer dqsck_min; integer dqsck_max; integer dqsq_min; integer dqsq_max; integer seed; // Mode Registers reg [ADDR_BITS-1:0] mode_reg [`BANKS-1:0]; reg burst_order; reg [BL_BITS:0] burst_length; reg blotf; reg truebl4; integer cas_latency; reg dll_reset; reg dll_locked; integer write_recovery; reg low_power; reg dll_en; reg [2:0] odt_rtt_nom; reg [1:0] odt_rtt_wr; reg odt_en; reg dyn_odt_en; reg [1:0] al; integer additive_latency; reg write_levelization; reg duty_cycle_corrector; reg tdqs_en; reg out_en; reg [2:0] pasr; integer cas_write_latency; reg asr; // auto self refresh reg srt; // self refresh temperature range reg [1:0] mpr_select; reg mpr_en; reg odts_readout; integer read_latency; integer write_latency; // cmd encoding parameter // {cs, ras, cas, we} LOAD_MODE = 4'b0000, REFRESH = 4'b0001, PRECHARGE = 4'b0010, ACTIVATE = 4'b0011, WRITE = 4'b0100, READ = 4'b0101, ZQ = 4'b0110, NOP = 4'b0111, // DESEL = 4'b1xxx, PWR_DOWN = 4'b1000, SELF_REF = 4'b1001 ; reg [8*9-1:0] cmd_string [9:0]; initial begin cmd_string[LOAD_MODE] = "Load Mode"; cmd_string[REFRESH ] = "Refresh "; cmd_string[PRECHARGE] = "Precharge"; cmd_string[ACTIVATE ] = "Activate "; cmd_string[WRITE ] = "Write "; cmd_string[READ ] = "Read "; cmd_string[ZQ ] = "ZQ "; cmd_string[NOP ] = "No Op "; cmd_string[PWR_DOWN ] = "Pwr Down "; cmd_string[SELF_REF ] = "Self Ref "; end // command state reg [`BANKS-1:0] active_bank; reg [`BANKS-1:0] auto_precharge_bank; reg [`BANKS-1:0] write_precharge_bank; reg [`BANKS-1:0] read_precharge_bank; reg [ROW_BITS-1:0] active_row [`BANKS-1:0]; reg in_power_down; reg in_self_refresh; reg [3:0] init_mode_reg; reg init_dll_reset; reg init_done; integer init_step; reg zq_set; reg er_trfc_max; reg odt_state; reg odt_state_dly; reg dyn_odt_state; reg dyn_odt_state_dly; reg prev_odt; wire [7:0] calibration_pattern = 8'b10101010; // value returned during mpr pre-defined pattern readout wire [7:0] temp_sensor = 8'h01; // value returned during mpr temp sensor readout reg [1:0] mr_chk; reg rd_bc; integer banki; // cmd timers/counters integer ref_cntr; integer odt_cntr; integer ck_cntr; integer ck_txpr; integer ck_load_mode; integer ck_refresh; integer ck_precharge; integer ck_activate; integer ck_write; integer ck_read; integer ck_zqinit; integer ck_zqoper; integer ck_zqcs; integer ck_power_down; integer ck_slow_exit_pd; integer ck_self_refresh; integer ck_freq_change; integer ck_odt; integer ck_odth8; integer ck_dll_reset; integer ck_cke_cmd; integer ck_bank_write [`BANKS-1:0]; integer ck_bank_read [`BANKS-1:0]; integer ck_group_activate [1:0]; integer ck_group_write [1:0]; integer ck_group_read [1:0]; time tm_txpr; time tm_load_mode; time tm_refresh; time tm_precharge; time tm_activate; time tm_write_end; time tm_power_down; time tm_slow_exit_pd; time tm_self_refresh; time tm_freq_change; time tm_cke_cmd; time tm_ttsinit; time tm_bank_precharge [`BANKS-1:0]; time tm_bank_activate [`BANKS-1:0]; time tm_bank_write_end [`BANKS-1:0]; time tm_bank_read_end [`BANKS-1:0]; time tm_group_activate [1:0]; time tm_group_write_end [1:0]; // pipelines reg [`MAX_PIPE:0] al_pipeline; reg [`MAX_PIPE:0] wr_pipeline; reg [`MAX_PIPE:0] rd_pipeline; reg [`MAX_PIPE:0] odt_pipeline; reg [`MAX_PIPE:0] dyn_odt_pipeline; reg [BL_BITS:0] bl_pipeline [`MAX_PIPE:0]; reg [BA_BITS-1:0] ba_pipeline [`MAX_PIPE:0]; reg [ROW_BITS-1:0] row_pipeline [`MAX_PIPE:0]; reg [COL_BITS-1:0] col_pipeline [`MAX_PIPE:0]; reg prev_cke; // data state reg [BL_MAX*DQ_BITS-1:0] memory_data; reg [BL_MAX*DQ_BITS-1:0] bit_mask; reg [BL_BITS-1:0] burst_position; reg [BL_BITS:0] burst_cntr; reg [DQ_BITS-1:0] dq_temp; reg [31:0] check_write_postamble; reg [31:0] check_write_preamble; reg [31:0] check_write_dqs_high; reg [31:0] check_write_dqs_low; reg [15:0] check_dm_tdipw; reg [63:0] check_dq_tdipw; // data timers/counters time tm_rst_n; time tm_cke; time tm_odt; time tm_tdqss; time tm_dm [15:0]; time tm_dqs [15:0]; time tm_dqs_pos [31:0]; time tm_dqss_pos [31:0]; time tm_dqs_neg [31:0]; time tm_dq [63:0]; time tm_cmd_addr [22:0]; reg [8*7-1:0] cmd_addr_string [22:0]; initial begin cmd_addr_string[ 0] = "CS_N "; cmd_addr_string[ 1] = "RAS_N "; cmd_addr_string[ 2] = "CAS_N "; cmd_addr_string[ 3] = "WE_N "; cmd_addr_string[ 4] = "BA 0 "; cmd_addr_string[ 5] = "BA 1 "; cmd_addr_string[ 6] = "BA 2 "; cmd_addr_string[ 7] = "ADDR 0"; cmd_addr_string[ 8] = "ADDR 1"; cmd_addr_string[ 9] = "ADDR 2"; cmd_addr_string[10] = "ADDR 3"; cmd_addr_string[11] = "ADDR 4"; cmd_addr_string[12] = "ADDR 5"; cmd_addr_string[13] = "ADDR 6"; cmd_addr_string[14] = "ADDR 7"; cmd_addr_string[15] = "ADDR 8"; cmd_addr_string[16] = "ADDR 9"; cmd_addr_string[17] = "ADDR 10"; cmd_addr_string[18] = "ADDR 11"; cmd_addr_string[19] = "ADDR 12"; cmd_addr_string[20] = "ADDR 13"; cmd_addr_string[21] = "ADDR 14"; cmd_addr_string[22] = "ADDR 15"; end reg [8*5-1:0] dqs_string [1:0]; initial begin dqs_string[0] = "DQS "; dqs_string[1] = "DQS_N"; end // Memory Storage `ifdef MAX_MEM parameter RFF_BITS = DQ_BITS*BL_MAX; // %z format uses 8 bytes for every 32 bits or less. parameter RFF_CHUNK = 8 * (RFF_BITS/32 + (RFF_BITS%32 ? 1 : 0)); reg [1024:1] tmp_model_dir; integer memfd[`BANKS-1:0]; initial begin : file_io_open integer bank; if (!$value$plusargs("model_data+%s", tmp_model_dir)) begin tmp_model_dir = "/tmp"; $display( "%m: at time %t WARNING: no +model_data option specified, using /tmp.", $time ); end for (bank = 0; bank < `BANKS; bank = bank + 1) memfd[bank] = open_bank_file(bank); end `else reg [BL_MAX*DQ_BITS-1:0] memory [0:`MEM_SIZE-1]; reg [`MAX_BITS-1:0] address [0:`MEM_SIZE-1]; reg [MEM_BITS:0] memory_index; reg [MEM_BITS:0] memory_used = 0; `endif // receive reg rst_n_in; reg ck_in; reg ck_n_in; reg cke_in; reg cs_n_in; reg ras_n_in; reg cas_n_in; reg we_n_in; reg [15:0] dm_in; reg [2:0] ba_in; reg [15:0] addr_in; reg [63:0] dq_in; reg [31:0] dqs_in; reg odt_in; reg [15:0] dm_in_pos; reg [15:0] dm_in_neg; reg [63:0] dq_in_pos; reg [63:0] dq_in_neg; reg dq_in_valid; reg dqs_in_valid; integer wdqs_cntr; integer wdq_cntr; integer wdqs_pos_cntr [31:0]; reg b2b_write; reg [BL_BITS:0] wr_burst_length; reg [31:0] prev_dqs_in; reg diff_ck; always @(rst_n ) rst_n_in <= #BUS_DELAY rst_n; always @(ck ) ck_in <= #BUS_DELAY ck; always @(ck_n ) ck_n_in <= #BUS_DELAY ck_n; always @(cke ) cke_in <= #BUS_DELAY cke; always @(cs_n ) cs_n_in <= #BUS_DELAY cs_n; always @(ras_n ) ras_n_in <= #BUS_DELAY ras_n; always @(cas_n ) cas_n_in <= #BUS_DELAY cas_n; always @(we_n ) we_n_in <= #BUS_DELAY we_n; always @(dm_tdqs) dm_in <= #BUS_DELAY dm_tdqs; always @(ba ) ba_in <= #BUS_DELAY ba; always @(addr ) addr_in <= #BUS_DELAY addr; always @(dq ) dq_in <= #BUS_DELAY dq; always @(dqs or dqs_n) dqs_in <= #BUS_DELAY (dqs_n<<16) | dqs; always @(odt ) odt_in <= #BUS_DELAY odt; // create internal clock always @(posedge ck_in) diff_ck <= ck_in; always @(posedge ck_n_in) diff_ck <= ~ck_n_in; wire [15:0] dqs_even = dqs_in[15:0]; wire [15:0] dqs_odd = dqs_in[31:16]; wire [3:0] cmd_n_in = !cs_n_in ? {ras_n_in, cas_n_in, we_n_in} : NOP; //deselect = nop // transmit reg dqs_out_en; reg [DQS_BITS-1:0] dqs_out_en_dly; reg dqs_out; reg [DQS_BITS-1:0] dqs_out_dly; reg dq_out_en; reg [DQ_BITS-1:0] dq_out_en_dly; reg [DQ_BITS-1:0] dq_out; reg [DQ_BITS-1:0] dq_out_dly; integer rdqsen_cntr; integer rdqs_cntr; integer rdqen_cntr; integer rdq_cntr; bufif1 buf_dqs [DQS_BITS-1:0] (dqs, dqs_out_dly, dqs_out_en_dly & {DQS_BITS{out_en}}); bufif1 buf_dqs_n [DQS_BITS-1:0] (dqs_n, ~dqs_out_dly, dqs_out_en_dly & {DQS_BITS{out_en}}); bufif1 buf_dq [DQ_BITS-1:0] (dq, dq_out_dly, dq_out_en_dly & {DQ_BITS {out_en}}); assign tdqs_n = {DQS_BITS{1'bz}}; initial begin if (BL_MAX < 2) $display("%m ERROR: BL_MAX parameter must be >= 2. \nBL_MAX = %d", BL_MAX); if ((1<<BO_BITS) > BL_MAX) $display("%m ERROR: 2^BO_BITS cannot be greater than BL_MAX parameter."); $timeformat (-12, 1, " ps", 1); seed = RANDOM_SEED; ck_cntr = 0; end function integer get_rtt_wr; input [1:0] rtt; begin get_rtt_wr = RZQ/{rtt[0], rtt[1], 1'b0}; end endfunction function integer get_rtt_nom; input [2:0] rtt; begin case (rtt) 1: get_rtt_nom = RZQ/4; 2: get_rtt_nom = RZQ/2; 3: get_rtt_nom = RZQ/6; 4: get_rtt_nom = RZQ/12; 5: get_rtt_nom = RZQ/8; default : get_rtt_nom = 0; endcase end endfunction // calculate the absolute value of a real number function real abs_value; input arg; real arg; begin if (arg < 0.0) abs_value = -1.0 * arg; else abs_value = arg; end endfunction function integer ceil; input number; real number; // LMR 4.1.7 // When either operand of a relational expression is a real operand then the other operand shall be converted // to an equivalent real value, and the expression shall be interpreted as a comparison between two real values. if (number > $rtoi(number)) ceil = $rtoi(number) + 1; else ceil = number; endfunction function integer floor; input number; real number; // LMR 4.1.7 // When either operand of a relational expression is a real operand then the other operand shall be converted // to an equivalent real value, and the expression shall be interpreted as a comparison between two real values. if (number < $rtoi(number)) floor = $rtoi(number) - 1; else floor = number; endfunction `ifdef MAX_MEM function integer open_bank_file( input integer bank ); integer fd; reg [2048:1] filename; begin $sformat( filename, "%0s/%m.%0d", tmp_model_dir, bank ); fd = $fopen(filename, "w+"); if (fd == 0) begin $display("%m: at time %0t ERROR: failed to open %0s.", $time, filename); $finish; end else begin if (DEBUG) $display("%m: at time %0t INFO: opening %0s.", $time, filename); open_bank_file = fd; end end endfunction function [RFF_BITS:1] read_from_file( input integer fd, input integer index ); integer code; integer offset; reg [1024:1] msg; reg [RFF_BITS:1] read_value; begin offset = index * RFF_CHUNK; code = $fseek( fd, offset, 0 ); // $fseek returns 0 on success, -1 on failure if (code != 0) begin $display("%m: at time %t ERROR: fseek to %d failed", $time, offset); $finish; end code = $fscanf(fd, "%z", read_value); // $fscanf returns number of items read if (code != 1) begin if ($ferror(fd,msg) != 0) begin $display("%m: at time %t ERROR: fscanf failed at %d", $time, index); $display(msg); $finish; end else read_value = 'hx; end /* when reading from unwritten portions of the file, 0 will be returned. * Use 0 in bit 1 as indicator that invalid data has been read. * A true 0 is encoded as Z. */ if (read_value[1] === 1'bz) // true 0 encoded as Z, data is valid read_value[1] = 1'b0; else if (read_value[1] === 1'b0) // read from file section that has not been written read_value = 'hx; read_from_file = read_value; end endfunction task write_to_file( input integer fd, input integer index, input [RFF_BITS:1] data ); integer code; integer offset; begin offset = index * RFF_CHUNK; code = $fseek( fd, offset, 0 ); if (code != 0) begin $display("%m: at time %t ERROR: fseek to %d failed", $time, offset); $finish; end // encode a valid data if (data[1] === 1'bz) data[1] = 1'bx; else if (data[1] === 1'b0) data[1] = 1'bz; $fwrite( fd, "%z", data ); end endtask `else function get_index; input [`MAX_BITS-1:0] addr; begin : index get_index = 0; for (memory_index=0; memory_index<memory_used; memory_index=memory_index+1) begin if (address[memory_index] == addr) begin get_index = 1; disable index; end end end endfunction `endif task memory_write; input [BA_BITS-1:0] bank; input [ROW_BITS-1:0] row; input [COL_BITS-1:0] col; input [BL_MAX*DQ_BITS-1:0] data; reg [`MAX_BITS-1:0] addr; begin `ifdef MAX_MEM addr = {row, col}/BL_MAX; write_to_file( memfd[bank], addr, data ); `else // chop off the lowest address bits addr = {bank, row, col}/BL_MAX; if (get_index(addr)) begin address[memory_index] = addr; memory[memory_index] = data; end else if (memory_used == `MEM_SIZE) begin $display ("%m: at time %t ERROR: Memory overflow. Write to Address %h with Data %h will be lost.\nYou must increase the MEM_BITS parameter or define MAX_MEM.", $time, addr, data); if (STOP_ON_ERROR) $stop(0); end else begin address[memory_used] = addr; memory[memory_used] = data; memory_used = memory_used + 1; end `endif end endtask task memory_read; input [BA_BITS-1:0] bank; input [ROW_BITS-1:0] row; input [COL_BITS-1:0] col; output [BL_MAX*DQ_BITS-1:0] data; reg [`MAX_BITS-1:0] addr; begin `ifdef MAX_MEM addr = {row, col}/BL_MAX; data = read_from_file( memfd[bank], addr ); `else // chop off the lowest address bits addr = {bank, row, col}/BL_MAX; if (get_index(addr)) begin data = memory[memory_index]; end else begin data = {BL_MAX*DQ_BITS{1'bx}}; end `endif end endtask task set_latency; begin if (al == 0) begin additive_latency = 0; end else begin additive_latency = cas_latency - al; end read_latency = cas_latency + additive_latency; write_latency = cas_write_latency + additive_latency; end endtask // this task will erase the contents of 0 or more banks task erase_banks; input [`BANKS-1:0] banks; //one select bit per bank reg [BA_BITS-1:0] ba; reg [`MAX_BITS-1:0] i; integer bank; begin `ifdef MAX_MEM for (bank = 0; bank < `BANKS; bank = bank + 1) if (banks[bank] === 1'b1) begin $fclose(memfd[bank]); memfd[bank] = open_bank_file(bank); end `else memory_index = 0; i = 0; // remove the selected banks for (memory_index=0; memory_index<memory_used; memory_index=memory_index+1) begin ba = (address[memory_index]>>(ROW_BITS+COL_BITS-BL_BITS)); if (!banks[ba]) begin //bank is selected to keep address[i] = address[memory_index]; memory[i] = memory[memory_index]; i = i + 1; end end // clean up the unused banks for (memory_index=i; memory_index<memory_used; memory_index=memory_index+1) begin address[memory_index] = 'bx; memory[memory_index] = {8*DQ_BITS{1'bx}}; end memory_used = i; `endif end endtask // Before this task runs, the model must be in a valid state for precharge power down and out of reset. // After this task runs, NOP commands must be issued until TZQINIT has been met task initialize; input [ADDR_BITS-1:0] mode_reg0; input [ADDR_BITS-1:0] mode_reg1; input [ADDR_BITS-1:0] mode_reg2; input [ADDR_BITS-1:0] mode_reg3; begin if (DEBUG) $display ("%m: at time %t INFO: Performing Initialization Sequence", $time); cmd_task(1, NOP, 'bx, 'bx); cmd_task(1, ZQ, 'bx, 'h400); //ZQCL cmd_task(1, LOAD_MODE, 3, mode_reg3); cmd_task(1, LOAD_MODE, 2, mode_reg2); cmd_task(1, LOAD_MODE, 1, mode_reg1); cmd_task(1, LOAD_MODE, 0, mode_reg0 | 'h100); // DLL Reset cmd_task(0, NOP, 'bx, 'bx); end endtask task reset_task; integer i; begin // disable inputs dq_in_valid = 0; dqs_in_valid <= 0; wdqs_cntr = 0; wdq_cntr = 0; for (i=0; i<31; i=i+1) begin wdqs_pos_cntr[i] <= 0; end b2b_write <= 0; // disable outputs out_en = 0; dq_out_en = 0; rdq_cntr = 0; dqs_out_en = 0; rdqs_cntr = 0; // disable ODT odt_en = 0; dyn_odt_en = 0; odt_state = 0; dyn_odt_state = 0; // reset bank state active_bank = 0; auto_precharge_bank = 0; read_precharge_bank = 0; write_precharge_bank = 0; // require initialization sequence init_done = 0; mpr_en = 0; init_step = 0; init_mode_reg = 0; init_dll_reset = 0; zq_set = 0; // reset DLL dll_en = 0; dll_reset = 0; dll_locked = 0; // exit power down and self refresh prev_cke = 1'bx; in_power_down = 0; in_self_refresh = 0; // clear pipelines al_pipeline = 0; wr_pipeline = 0; rd_pipeline = 0; odt_pipeline = 0; dyn_odt_pipeline = 0; end endtask parameter SAME_BANK = 2'd0; // same bank, same group parameter DIFF_BANK = 2'd1; // different bank, same group parameter DIFF_GROUP = 2'd2; // different bank, different group task chk_err; input [1:0] relationship; input [BA_BITS-1:0] bank; input [3:0] fromcmd; input [3:0] cmd; reg err; begin // $display ("truebl4 = %d, relationship = %d, fromcmd = %h, cmd = %h", truebl4, relationship, fromcmd, cmd); casex ({truebl4, relationship, fromcmd, cmd}) // load mode {1'bx, DIFF_BANK , LOAD_MODE, LOAD_MODE} : begin if (ck_cntr - ck_load_mode < TMRD) $display ("%m: at time %t ERROR: tMRD violation during %s", $time, cmd_string[cmd]); end {1'bx, DIFF_BANK , LOAD_MODE, READ } : begin if (($time - tm_load_mode < TMOD) || (ck_cntr - ck_load_mode < TMOD_TCK)) $display ("%m: at time %t ERROR: tMOD violation during %s", $time, cmd_string[cmd]); end {1'bx, DIFF_BANK , LOAD_MODE, REFRESH } , {1'bx, DIFF_BANK , LOAD_MODE, PRECHARGE} , {1'bx, DIFF_BANK , LOAD_MODE, ACTIVATE } , {1'bx, DIFF_BANK , LOAD_MODE, ZQ } , {1'bx, DIFF_BANK , LOAD_MODE, PWR_DOWN } , {1'bx, DIFF_BANK , LOAD_MODE, SELF_REF } : begin if (($time - tm_load_mode < TMOD) || (ck_cntr - ck_load_mode < TMOD_TCK)) $display ("%m: at time %t ERROR: tMOD violation during %s", $time, cmd_string[cmd]); end // refresh {1'bx, DIFF_BANK , REFRESH , LOAD_MODE} , {1'bx, DIFF_BANK , REFRESH , REFRESH } , {1'bx, DIFF_BANK , REFRESH , PRECHARGE} , {1'bx, DIFF_BANK , REFRESH , ACTIVATE } , {1'bx, DIFF_BANK , REFRESH , ZQ } , {1'bx, DIFF_BANK , REFRESH , SELF_REF } : begin if ($time - tm_refresh < TRFC_MIN) $display ("%m: at time %t ERROR: tRFC violation during %s", $time, cmd_string[cmd]); end {1'bx, DIFF_BANK , REFRESH , PWR_DOWN } : begin if (ck_cntr - ck_refresh < TREFPDEN) $display ("%m: at time %t ERROR: tREFPDEN violation during %s", $time, cmd_string[cmd]); end // precharge {1'bx, SAME_BANK , PRECHARGE, ACTIVATE } : begin if ($time - tm_bank_precharge[bank] < TRP) $display ("%m: at time %t ERROR: tRP violation during %s to bank %d", $time, cmd_string[cmd], bank); end {1'bx, DIFF_BANK , PRECHARGE, LOAD_MODE} , {1'bx, DIFF_BANK , PRECHARGE, REFRESH } , {1'bx, DIFF_BANK , PRECHARGE, ZQ } , {1'bx, DIFF_BANK , PRECHARGE, SELF_REF } : begin if ($time - tm_precharge < TRP) $display ("%m: at time %t ERROR: tRP violation during %s", $time, cmd_string[cmd]); end {1'bx, DIFF_BANK , PRECHARGE, PWR_DOWN } : ; //tPREPDEN = 1 tCK, can be concurrent with auto precharge // activate {1'bx, SAME_BANK , ACTIVATE , PRECHARGE} : begin if ($time - tm_bank_activate[bank] > TRAS_MAX) $display ("%m: at time %t ERROR: tRAS maximum violation during %s to bank %d", $time, cmd_string[cmd], bank); if ($time - tm_bank_activate[bank] < TRAS_MIN) $display ("%m: at time %t ERROR: tRAS minimum violation during %s to bank %d", $time, cmd_string[cmd], bank);end {1'bx, SAME_BANK , ACTIVATE , ACTIVATE } : begin if ($time - tm_bank_activate[bank] < TRC) $display ("%m: at time %t ERROR: tRC violation during %s to bank %d", $time, cmd_string[cmd], bank); end {1'bx, SAME_BANK , ACTIVATE , WRITE } , {1'bx, SAME_BANK , ACTIVATE , READ } : ; // tRCD is checked outside this task {1'b0, DIFF_BANK , ACTIVATE , ACTIVATE } : begin if (($time - tm_activate < TRRD) || (ck_cntr - ck_activate < TRRD_TCK)) $display ("%m: at time %t ERROR: tRRD violation during %s to bank %d", $time, cmd_string[cmd], bank); end {1'b1, DIFF_BANK , ACTIVATE , ACTIVATE } : begin if (($time - tm_group_activate[bank[1]] < TRRD) || (ck_cntr - ck_group_activate[bank[1]] < TRRD_TCK)) $display ("%m: at time %t ERROR: tRRD violation during %s to bank %d", $time, cmd_string[cmd], bank); end {1'b1, DIFF_GROUP, ACTIVATE , ACTIVATE } : begin if (($time - tm_activate < TRRD_DG) || (ck_cntr - ck_activate < TRRD_DG_TCK)) $display ("%m: at time %t ERROR: tRRD_DG violation during %s to bank %d", $time, cmd_string[cmd], bank); end {1'bx, DIFF_BANK , ACTIVATE , REFRESH } : begin if ($time - tm_activate < TRC) $display ("%m: at time %t ERROR: tRC violation during %s", $time, cmd_string[cmd]); end {1'bx, DIFF_BANK , ACTIVATE , PWR_DOWN } : begin if (ck_cntr - ck_activate < TACTPDEN) $display ("%m: at time %t ERROR: tACTPDEN violation during %s", $time, cmd_string[cmd]); end // write {1'bx, SAME_BANK , WRITE , PRECHARGE} : begin if (($time - tm_bank_write_end[bank] < TWR) || (ck_cntr - ck_bank_write[bank] <= write_latency + burst_length/2)) $display ("%m: at time %t ERROR: tWR violation during %s to bank %d", $time, cmd_string[cmd], bank); end {1'b0, DIFF_BANK , WRITE , WRITE } : begin if (ck_cntr - ck_write < TCCD) $display ("%m: at time %t ERROR: tCCD violation during %s to bank %d", $time, cmd_string[cmd], bank); end {1'b1, DIFF_BANK , WRITE , WRITE } : begin if (ck_cntr - ck_group_write[bank[1]] < TCCD) $display ("%m: at time %t ERROR: tCCD violation during %s to bank %d", $time, cmd_string[cmd], bank); end {1'b0, DIFF_BANK , WRITE , READ } : begin if (ck_cntr - ck_write < write_latency + burst_length/2 + TWTR_TCK - additive_latency) $display ("%m: at time %t ERROR: tWTR violation during %s to bank %d", $time, cmd_string[cmd], bank); end {1'b1, DIFF_BANK , WRITE , READ } : begin if (ck_cntr - ck_group_write[bank[1]] < write_latency + burst_length/2 + TWTR_TCK - additive_latency) $display ("%m: at time %t ERROR: tWTR violation during %s to bank %d", $time, cmd_string[cmd], bank); end {1'b1, DIFF_GROUP, WRITE , WRITE } : begin if (ck_cntr - ck_write < TCCD_DG) $display ("%m: at time %t ERROR: tCCD_DG violation during %s to bank %d", $time, cmd_string[cmd], bank); end {1'b1, DIFF_GROUP, WRITE , READ } : begin if (ck_cntr - ck_write < write_latency + burst_length/2 + TWTR_DG_TCK - additive_latency) $display ("%m: at time %t ERROR: tWTR_DG violation during %s to bank %d", $time, cmd_string[cmd], bank); end {1'bx, DIFF_BANK , WRITE , PWR_DOWN } : begin if (($time - tm_write_end < TWR) || (ck_cntr - ck_write < write_latency + burst_length/2)) $display ("%m: at time %t ERROR: tWRPDEN violation during %s", $time, cmd_string[cmd]); end // read {1'bx, SAME_BANK , READ , PRECHARGE} : begin if (($time - tm_bank_read_end[bank] < TRTP) || (ck_cntr - ck_bank_read[bank] < additive_latency + TRTP_TCK)) $display ("%m: at time %t ERROR: tRTP violation during %s to bank %d", $time, cmd_string[cmd], bank); end {1'b0, DIFF_BANK , READ , WRITE } : ; // tRTW is checked outside this task {1'b1, DIFF_BANK , READ , WRITE } : ; // tRTW is checked outside this task {1'b0, DIFF_BANK , READ , READ } : begin if (ck_cntr - ck_read < TCCD) $display ("%m: at time %t ERROR: tCCD violation during %s to bank %d", $time, cmd_string[cmd], bank); end {1'b1, DIFF_BANK , READ , READ } : begin if (ck_cntr - ck_group_read[bank[1]] < TCCD) $display ("%m: at time %t ERROR: tCCD violation during %s to bank %d", $time, cmd_string[cmd], bank); end {1'b1, DIFF_GROUP, READ , WRITE } : ; // tRTW is checked outside this task {1'b1, DIFF_GROUP, READ , READ } : begin if (ck_cntr - ck_read < TCCD_DG) $display ("%m: at time %t ERROR: tCCD_DG violation during %s to bank %d", $time, cmd_string[cmd], bank); end {1'bx, DIFF_BANK , READ , PWR_DOWN } : begin if (ck_cntr - ck_read < read_latency + 5) $display ("%m: at time %t ERROR: tRDPDEN violation during %s", $time, cmd_string[cmd]); end // zq {1'bx, DIFF_BANK , ZQ , LOAD_MODE} : ; // 1 tCK {1'bx, DIFF_BANK , ZQ , REFRESH } , {1'bx, DIFF_BANK , ZQ , PRECHARGE} , {1'bx, DIFF_BANK , ZQ , ACTIVATE } , {1'bx, DIFF_BANK , ZQ , ZQ } , {1'bx, DIFF_BANK , ZQ , PWR_DOWN } , {1'bx, DIFF_BANK , ZQ , SELF_REF } : begin if (ck_cntr - ck_zqinit < TZQINIT) $display ("%m: at time %t ERROR: tZQinit violation during %s", $time, cmd_string[cmd]); if (ck_cntr - ck_zqoper < TZQOPER) $display ("%m: at time %t ERROR: tZQoper violation during %s", $time, cmd_string[cmd]); if (ck_cntr - ck_zqcs < TZQCS) $display ("%m: at time %t ERROR: tZQCS violation during %s", $time, cmd_string[cmd]); end // power down {1'bx, DIFF_BANK , PWR_DOWN , LOAD_MODE} , {1'bx, DIFF_BANK , PWR_DOWN , REFRESH } , {1'bx, DIFF_BANK , PWR_DOWN , PRECHARGE} , {1'bx, DIFF_BANK , PWR_DOWN , ACTIVATE } , {1'bx, DIFF_BANK , PWR_DOWN , WRITE } , {1'bx, DIFF_BANK , PWR_DOWN , ZQ } : begin if (($time - tm_power_down < TXP) || (ck_cntr - ck_power_down < TXP_TCK)) $display ("%m: at time %t ERROR: tXP violation during %s", $time, cmd_string[cmd]); end {1'bx, DIFF_BANK , PWR_DOWN , READ } : begin if (($time - tm_power_down < TXP) || (ck_cntr - ck_power_down < TXP_TCK)) $display ("%m: at time %t ERROR: tXP violation during %s", $time, cmd_string[cmd]); else if (($time - tm_slow_exit_pd < TXPDLL) || (ck_cntr - ck_slow_exit_pd < TXPDLL_TCK)) $display ("%m: at time %t ERROR: tXPDLL violation during %s", $time, cmd_string[cmd]); end {1'bx, DIFF_BANK , PWR_DOWN , PWR_DOWN } , {1'bx, DIFF_BANK , PWR_DOWN , SELF_REF } : begin if (($time - tm_power_down < TXP) || (ck_cntr - ck_power_down < TXP_TCK)) $display ("%m: at time %t ERROR: tXP violation during %s", $time, cmd_string[cmd]); if ((tm_power_down > tm_refresh) && ($time - tm_refresh < TRFC_MIN)) $display ("%m: at time %t ERROR: tRFC violation during %s", $time, cmd_string[cmd]); if ((tm_refresh > tm_power_down) && (($time - tm_power_down < TXPDLL) || (ck_cntr - ck_power_down < TXPDLL_TCK))) $display ("%m: at time %t ERROR: tXPDLL violation during %s", $time, cmd_string[cmd]); if (($time - tm_cke_cmd < TCKE) || (ck_cntr - ck_cke_cmd < TCKE_TCK)) $display ("%m: at time %t ERROR: tCKE violation on CKE", $time); end // self refresh {1'bx, DIFF_BANK , SELF_REF , LOAD_MODE} , {1'bx, DIFF_BANK , SELF_REF , REFRESH } , {1'bx, DIFF_BANK , SELF_REF , PRECHARGE} , {1'bx, DIFF_BANK , SELF_REF , ACTIVATE } , {1'bx, DIFF_BANK , SELF_REF , WRITE } , {1'bx, DIFF_BANK , SELF_REF , ZQ } : begin if (($time - tm_self_refresh < TXS) || (ck_cntr - ck_self_refresh < TXS_TCK)) $display ("%m: at time %t ERROR: tXS violation during %s", $time, cmd_string[cmd]); end {1'bx, DIFF_BANK , SELF_REF , READ } : begin if (ck_cntr - ck_self_refresh < TXSDLL) $display ("%m: at time %t ERROR: tXSDLL violation during %s", $time, cmd_string[cmd]); end {1'bx, DIFF_BANK , SELF_REF , PWR_DOWN } , {1'bx, DIFF_BANK , SELF_REF , SELF_REF } : begin if (($time - tm_self_refresh < TXS) || (ck_cntr - ck_self_refresh < TXS_TCK)) $display ("%m: at time %t ERROR: tXS violation during %s", $time, cmd_string[cmd]); if (($time - tm_cke_cmd < TCKE) || (ck_cntr - ck_cke_cmd < TCKE_TCK)) $display ("%m: at time %t ERROR: tCKE violation on CKE", $time); end endcase end endtask task cmd_task; input cke; input [2:0] cmd; input [BA_BITS-1:0] bank; input [ADDR_BITS-1:0] addr; reg [`BANKS:0] i; integer j; reg [`BANKS:0] tfaw_cntr; reg [COL_BITS-1:0] col; reg group; begin // tRFC max check if (!er_trfc_max && !in_self_refresh) begin if ($time - tm_refresh > TRFC_MAX && check_strict_timing) begin $display ("%m: at time %t ERROR: tRFC maximum violation during %s", $time, cmd_string[cmd]); er_trfc_max = 1; end end if (cke) begin if ((cmd < NOP) && (cmd != PRECHARGE)) begin if (($time - tm_txpr < TXPR) || (ck_cntr - ck_txpr < TXPR_TCK)) $display ("%m: at time %t ERROR: tXPR violation during %s", $time, cmd_string[cmd]); for (j=0; j<=SELF_REF; j=j+1) begin chk_err(SAME_BANK , bank, j, cmd); chk_err(DIFF_BANK , bank, j, cmd); chk_err(DIFF_GROUP, bank, j, cmd); end end case (cmd) LOAD_MODE : begin if (|odt_pipeline) $display ("%m: at time %t ERROR: ODTL violation during %s", $time, cmd_string[cmd]); if (odt_state) $display ("%m: at time %t ERROR: ODT must be off prior to %s", $time, cmd_string[cmd]); if (|active_bank) begin $display ("%m: at time %t ERROR: %s Failure. All banks must be Precharged.", $time, cmd_string[cmd]); if (STOP_ON_ERROR) $stop(0); end else begin if (DEBUG) $display ("%m: at time %t INFO: %s %d", $time, cmd_string[cmd], bank); if (bank>>2) begin $display ("%m: at time %t ERROR: %s %d Illegal value. Reserved bank bits must be programmed to zero", $time, cmd_string[cmd], bank); end case (bank) 0 : begin // Burst Length if (addr[1:0] == 2'b00) begin burst_length = 8; blotf = 0; truebl4 = 0; if (DEBUG) $display ("%m: at time %t INFO: %s %d Burst Length = %d", $time, cmd_string[cmd], bank, burst_length); end else if (addr[1:0] == 2'b01) begin burst_length = 8; blotf = 1; truebl4 = 0; if (DEBUG) $display ("%m: at time %t INFO: %s %d Burst Length = Select via A12", $time, cmd_string[cmd], bank); end else if (addr[1:0] == 2'b10) begin burst_length = 4; blotf = 0; truebl4 = 0; if (DEBUG) $display ("%m: at time %t INFO: %s %d Burst Length = Fixed %d (chop)", $time, cmd_string[cmd], bank, burst_length); end else if (feature_truebl4 && (addr[1:0] == 2'b11)) begin burst_length = 4; blotf = 0; truebl4 = 1; if (DEBUG) $display ("%m: at time %t INFO: %s %d Burst Length = True %d", $time, cmd_string[cmd], bank, burst_length); end else begin $display ("%m: at time %t ERROR: %s %d Illegal Burst Length = %d", $time, cmd_string[cmd], bank, addr[1:0]); end // Burst Order burst_order = addr[3]; if (!burst_order) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d Burst Order = Sequential", $time, cmd_string[cmd], bank); end else if (burst_order) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d Burst Order = Interleaved", $time, cmd_string[cmd], bank); end else begin $display ("%m: at time %t ERROR: %s %d Illegal Burst Order = %d", $time, cmd_string[cmd], bank, burst_order); end // CAS Latency cas_latency = {addr[2],addr[6:4]} + 4; set_latency; if ((cas_latency >= CL_MIN) && (cas_latency <= CL_MAX)) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d CAS Latency = %d", $time, cmd_string[cmd], bank, cas_latency); end else begin $display ("%m: at time %t ERROR: %s %d Illegal CAS Latency = %d", $time, cmd_string[cmd], bank, cas_latency); end // Reserved if (addr[7] !== 0 && check_strict_mrbits) begin $display ("%m: at time %t ERROR: %s %d Illegal value. Reserved address bits must be programmed to zero", $time, cmd_string[cmd], bank); end // DLL Reset dll_reset = addr[8]; if (!dll_reset) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d DLL Reset = Normal", $time, cmd_string[cmd], bank); end else if (dll_reset) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d DLL Reset = Reset DLL", $time, cmd_string[cmd], bank); dll_locked = 0; init_dll_reset = 1; ck_dll_reset <= ck_cntr; end else begin $display ("%m: at time %t ERROR: %s %d Illegal DLL Reset = %d", $time, cmd_string[cmd], bank, dll_reset); end // Write Recovery if (addr[11:9] == 0) begin write_recovery = 16; end else if (addr[11:9] < 4) begin write_recovery = addr[11:9] + 4; end else begin write_recovery = 2*addr[11:9]; end if ((write_recovery >= WR_MIN) && (write_recovery <= WR_MAX)) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d Write Recovery = %d", $time, cmd_string[cmd], bank, write_recovery); end else begin $display ("%m: at time %t ERROR: %s %d Illegal Write Recovery = %d", $time, cmd_string[cmd], bank, write_recovery); end // Power Down Mode low_power = !addr[12]; if (!low_power) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d Power Down Mode = DLL on", $time, cmd_string[cmd], bank); end else if (low_power) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d Power Down Mode = DLL off", $time, cmd_string[cmd], bank); end else begin $display ("%m: at time %t ERROR: %s %d Illegal Power Down Mode = %d", $time, cmd_string[cmd], bank, low_power); end // Reserved if (ADDR_BITS>13 && addr[13] !== 0 && check_strict_mrbits) begin $display ("%m: at time %t ERROR: %s %d Illegal value. Reserved address bits must be programmed to zero", $time, cmd_string[cmd], bank); end end 1 : begin // DLL Enable dll_en = !addr[0]; if (!dll_en) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d DLL Enable = Disabled", $time, cmd_string[cmd], bank); if (check_strict_mrbits) $display ("%m: at time %t WARNING: %s %d DLL off mode is not modeled", $time, cmd_string[cmd], bank); end else if (dll_en) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d DLL Enable = Enabled", $time, cmd_string[cmd], bank); end else begin $display ("%m: at time %t ERROR: %s %d Illegal DLL Enable = %d", $time, cmd_string[cmd], bank, dll_en); end // Output Drive Strength if ({addr[5], addr[1]} == 2'b00) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d Output Drive Strength = %d Ohm", $time, cmd_string[cmd], bank, RZQ/6); end else if ({addr[5], addr[1]} == 2'b01) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d Output Drive Strength = %d Ohm", $time, cmd_string[cmd], bank, RZQ/7); end else if ({addr[5], addr[1]} == 2'b11) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d Output Drive Strength = %d Ohm", $time, cmd_string[cmd], bank, RZQ/5); end else begin $display ("%m: at time %t ERROR: %s %d Illegal Output Drive Strength = %d", $time, cmd_string[cmd], bank, {addr[5], addr[1]}); end // ODT Rtt (Rtt_NOM) odt_rtt_nom = {addr[9], addr[6], addr[2]}; if (odt_rtt_nom == 3'b000) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d ODT Rtt = Disabled", $time, cmd_string[cmd], bank); odt_en = 0; end else if ((odt_rtt_nom < 4) || ((!addr[7] || (addr[7] && addr[12])) && (odt_rtt_nom < 6))) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d ODT Rtt = %d Ohm", $time, cmd_string[cmd], bank, get_rtt_nom(odt_rtt_nom)); odt_en = 1; end else begin $display ("%m: at time %t ERROR: %s %d Illegal ODT Rtt = %d", $time, cmd_string[cmd], bank, odt_rtt_nom); odt_en = 0; end // Report the additive latency value al = addr[4:3]; set_latency; if (al == 0) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d Additive Latency = %d", $time, cmd_string[cmd], bank, al); end else if ((al >= AL_MIN) && (al <= AL_MAX)) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d Additive Latency = CL - %d", $time, cmd_string[cmd], bank, al); end else begin $display ("%m: at time %t ERROR: %s %d Illegal Additive Latency = %d", $time, cmd_string[cmd], bank, al); end // Write Levelization write_levelization = addr[7]; if (!write_levelization) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d Write Levelization = Disabled", $time, cmd_string[cmd], bank); end else if (write_levelization) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d Write Levelization = Enabled", $time, cmd_string[cmd], bank); end else begin $display ("%m: at time %t ERROR: %s %d Illegal Write Levelization = %d", $time, cmd_string[cmd], bank, write_levelization); end // Reserved if (addr[8] !== 0 && check_strict_mrbits) begin $display ("%m: at time %t ERROR: %s %d Illegal value. Reserved address bits must be programmed to zero", $time, cmd_string[cmd], bank); end // Reserved if (addr[10] !== 0 && check_strict_mrbits) begin $display ("%m: at time %t ERROR: %s %d Illegal value. Reserved address bits must be programmed to zero", $time, cmd_string[cmd], bank); end // TDQS Enable tdqs_en = addr[11]; if (!tdqs_en) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d TDQS Enable = Disabled", $time, cmd_string[cmd], bank); end else if (tdqs_en) begin if (8 == DQ_BITS) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d TDQS Enable = Enabled", $time, cmd_string[cmd], bank); end else begin $display ("%m: at time %t WARNING: %s %d Illegal TDQS Enable. TDQS only exists on a x8 part", $time, cmd_string[cmd], bank); tdqs_en = 0; end end else begin $display ("%m: at time %t ERROR: %s %d Illegal TDQS Enable = %d", $time, cmd_string[cmd], bank, tdqs_en); end // Output Enable out_en = !addr[12]; if (!out_en) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d Qoff = Disabled", $time, cmd_string[cmd], bank); end else if (out_en) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d Qoff = Enabled", $time, cmd_string[cmd], bank); end else begin $display ("%m: at time %t ERROR: %s %d Illegal Qoff = %d", $time, cmd_string[cmd], bank, out_en); end // Reserved if (ADDR_BITS>13 && addr[13] !== 0 && check_strict_mrbits) begin $display ("%m: at time %t ERROR: %s %d Illegal value. Reserved address bits must be programmed to zero", $time, cmd_string[cmd], bank); end end 2 : begin if (feature_pasr) begin // Partial Array Self Refresh pasr = addr[2:0]; case (pasr) 3'b000 : if (DEBUG) $display ("%m: at time %t INFO: %s %d Partial Array Self Refresh = Bank 0-7", $time, cmd_string[cmd], bank); 3'b001 : if (DEBUG) $display ("%m: at time %t INFO: %s %d Partial Array Self Refresh = Bank 0-3", $time, cmd_string[cmd], bank); 3'b010 : if (DEBUG) $display ("%m: at time %t INFO: %s %d Partial Array Self Refresh = Bank 0-1", $time, cmd_string[cmd], bank); 3'b011 : if (DEBUG) $display ("%m: at time %t INFO: %s %d Partial Array Self Refresh = Bank 0", $time, cmd_string[cmd], bank); 3'b100 : if (DEBUG) $display ("%m: at time %t INFO: %s %d Partial Array Self Refresh = Bank 2-7", $time, cmd_string[cmd], bank); 3'b101 : if (DEBUG) $display ("%m: at time %t INFO: %s %d Partial Array Self Refresh = Bank 4-7", $time, cmd_string[cmd], bank); 3'b110 : if (DEBUG) $display ("%m: at time %t INFO: %s %d Partial Array Self Refresh = Bank 6-7", $time, cmd_string[cmd], bank); 3'b111 : if (DEBUG) $display ("%m: at time %t INFO: %s %d Partial Array Self Refresh = Bank 7", $time, cmd_string[cmd], bank); default : $display ("%m: at time %t ERROR: %s %d Illegal Partial Array Self Refresh = %d", $time, cmd_string[cmd], bank, pasr); endcase end else if (addr[2:0] !== 0 && check_strict_mrbits) begin $display ("%m: at time %t ERROR: %s %d Illegal value. Reserved address bits must be programmed to zero", $time, cmd_string[cmd], bank); end // CAS Write Latency cas_write_latency = addr[5:3]+5; set_latency; if ((cas_write_latency >= CWL_MIN) && (cas_write_latency <= CWL_MAX)) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d CAS Write Latency = %d", $time, cmd_string[cmd], bank, cas_write_latency); end else begin $display ("%m: at time %t ERROR: %s %d Illegal CAS Write Latency = %d", $time, cmd_string[cmd], bank, cas_write_latency); end // Auto Self Refresh Method asr = addr[6]; if (!asr) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d Auto Self Refresh = Disabled", $time, cmd_string[cmd], bank); end else if (asr) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d Auto Self Refresh = Enabled", $time, cmd_string[cmd], bank); if (check_strict_mrbits) $display ("%m: at time %t WARNING: %s %d Auto Self Refresh is not modeled", $time, cmd_string[cmd], bank); end else begin $display ("%m: at time %t ERROR: %s %d Illegal Auto Self Refresh = %d", $time, cmd_string[cmd], bank, asr); end // Self Refresh Temperature srt = addr[7]; if (!srt) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d Self Refresh Temperature = Normal", $time, cmd_string[cmd], bank); end else if (srt) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d Self Refresh Temperature = Extended", $time, cmd_string[cmd], bank); if (check_strict_mrbits) $display ("%m: at time %t WARNING: %s %d Self Refresh Temperature is not modeled", $time, cmd_string[cmd], bank); end else begin $display ("%m: at time %t ERROR: %s %d Illegal Self Refresh Temperature = %d", $time, cmd_string[cmd], bank, srt); end if (asr && srt) $display ("%m: at time %t ERROR: %s %d SRT must be set to 0 when ASR is enabled.", $time, cmd_string[cmd], bank); // Reserved if (addr[8] !== 0 && check_strict_mrbits) begin $display ("%m: at time %t ERROR: %s %d Illegal value. Reserved address bits must be programmed to zero", $time, cmd_string[cmd], bank); end // Dynamic ODT (Rtt_WR) odt_rtt_wr = addr[10:9]; if (odt_rtt_wr == 2'b00) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d Dynamic ODT = Disabled", $time, cmd_string[cmd], bank); dyn_odt_en = 0; end else if ((odt_rtt_wr > 0) && (odt_rtt_wr < 3)) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d Dynamic ODT Rtt = %d Ohm", $time, cmd_string[cmd], bank, get_rtt_wr(odt_rtt_wr)); dyn_odt_en = 1; end else begin $display ("%m: at time %t ERROR: %s %d Illegal Dynamic ODT = %d", $time, cmd_string[cmd], bank, odt_rtt_wr); dyn_odt_en = 0; end // Reserved if (ADDR_BITS>13 && addr[13:11] !== 0 && check_strict_mrbits) begin $display ("%m: at time %t ERROR: %s %d Illegal value. Reserved address bits must be programmed to zero", $time, cmd_string[cmd], bank); end end 3 : begin mpr_select = addr[1:0]; // MultiPurpose Register Select if (mpr_select == 2'b00) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d MultiPurpose Register Select = Pre-defined pattern", $time, cmd_string[cmd], bank); end else begin if (check_strict_mrbits) $display ("%m: at time %t ERROR: %s %d Illegal MultiPurpose Register Select = %d", $time, cmd_string[cmd], bank, mpr_select); end // MultiPurpose Register Enable mpr_en = addr[2]; if (!mpr_en) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d MultiPurpose Register Enable = Disabled", $time, cmd_string[cmd], bank); end else if (mpr_en) begin if (DEBUG) $display ("%m: at time %t INFO: %s %d MultiPurpose Register Enable = Enabled", $time, cmd_string[cmd], bank); end else begin $display ("%m: at time %t ERROR: %s %d Illegal MultiPurpose Register Enable = %d", $time, cmd_string[cmd], bank, mpr_en); end // Reserved if (ADDR_BITS>13 && addr[13:3] !== 0 && check_strict_mrbits) begin $display ("%m: at time %t ERROR: %s %d Illegal value. Reserved address bits must be programmed to zero", $time, cmd_string[cmd], bank); end end endcase if (dyn_odt_en && write_levelization) $display ("%m: at time %t ERROR: Dynamic ODT is not available during Write Leveling mode.", $time); init_mode_reg[bank] = 1; mode_reg[bank] = addr; tm_load_mode <= $time; ck_load_mode <= ck_cntr; end end REFRESH : begin if (mpr_en) begin $display ("%m: at time %t ERROR: %s Failure. Multipurpose Register must be disabled.", $time, cmd_string[cmd]); if (STOP_ON_ERROR) $stop(0); end else if (|active_bank) begin $display ("%m: at time %t ERROR: %s Failure. All banks must be Precharged.", $time, cmd_string[cmd]); if (STOP_ON_ERROR) $stop(0); end else begin if (DEBUG) $display ("%m: at time %t INFO: %s", $time, cmd_string[cmd]); er_trfc_max = 0; ref_cntr = ref_cntr + 1; tm_refresh <= $time; ck_refresh <= ck_cntr; end end PRECHARGE : begin if (addr[AP]) begin if (DEBUG) $display ("%m: at time %t INFO: %s All", $time, cmd_string[cmd]); end // PRECHARGE command will be treated as a NOP if there is no open row in that bank (idle state), // or if the previously open row is already in the process of precharging if (|active_bank) begin if (($time - tm_txpr < TXPR) || (ck_cntr - ck_txpr < TXPR_TCK)) $display ("%m: at time %t ERROR: tXPR violation during %s", $time, cmd_string[cmd]); if (mpr_en) begin $display ("%m: at time %t ERROR: %s Failure. Multipurpose Register must be disabled.", $time, cmd_string[cmd]); if (STOP_ON_ERROR) $stop(0); end else begin for (i=0; i<`BANKS; i=i+1) begin if (active_bank[i]) begin if (addr[AP] || (i == bank)) begin for (j=0; j<=SELF_REF; j=j+1) begin chk_err(SAME_BANK, i, j, cmd); chk_err(DIFF_BANK, i, j, cmd); end if (auto_precharge_bank[i]) begin $display ("%m: at time %t ERROR: %s Failure. Auto Precharge is scheduled to bank %d.", $time, cmd_string[cmd], i); if (STOP_ON_ERROR) $stop(0); end else begin if (DEBUG) $display ("%m: at time %t INFO: %s bank %d", $time, cmd_string[cmd], i); active_bank[i] = 1'b0; tm_bank_precharge[i] <= $time; tm_precharge <= $time; ck_precharge <= ck_cntr; end end end end end end end ACTIVATE : begin tfaw_cntr = 0; for (i=0; i<`BANKS; i=i+1) begin if ($time - tm_bank_activate[i] < TFAW) begin tfaw_cntr = tfaw_cntr + 1; end end if (tfaw_cntr > 3) begin $display ("%m: at time %t ERROR: tFAW violation during %s to bank %d", $time, cmd_string[cmd], bank); end if (mpr_en) begin $display ("%m: at time %t ERROR: %s Failure. Multipurpose Register must be disabled.", $time, cmd_string[cmd]); if (STOP_ON_ERROR) $stop(0); end else if (!init_done) begin $display ("%m: at time %t ERROR: %s Failure. Initialization sequence is not complete.", $time, cmd_string[cmd]); if (STOP_ON_ERROR) $stop(0); end else if (active_bank[bank]) begin $display ("%m: at time %t ERROR: %s Failure. Bank %d must be Precharged.", $time, cmd_string[cmd], bank); if (STOP_ON_ERROR) $stop(0); end else begin if (addr >= 1<<ROW_BITS) begin $display ("%m: at time %t WARNING: row = %h does not exist. Maximum row = %h", $time, addr, (1<<ROW_BITS)-1); end if (DEBUG) $display ("%m: at time %t INFO: %s bank %d row %h", $time, cmd_string[cmd], bank, addr); active_bank[bank] = 1'b1; active_row[bank] = addr; tm_group_activate[bank[1]] <= $time; tm_activate <= $time; tm_bank_activate[bank] <= $time; ck_group_activate[bank[1]] <= ck_cntr; ck_activate <= ck_cntr; end end WRITE : begin if ((!rd_bc && blotf) || (burst_length == 4)) begin // BL=4 if (truebl4) begin if (ck_cntr - ck_group_read[bank[1]] < read_latency + TCCD/2 + 2 - write_latency) $display ("%m: at time %t ERROR: tRTW violation during %s to bank %d", $time, cmd_string[cmd], bank); if (ck_cntr - ck_read < read_latency + TCCD_DG/2 + 2 - write_latency) $display ("%m: at time %t ERROR: tRTW_DG violation during %s to bank %d", $time, cmd_string[cmd], bank); end else begin if (ck_cntr - ck_read < read_latency + TCCD/2 + 2 - write_latency) $display ("%m: at time %t ERROR: tRTW violation during %s to bank %d", $time, cmd_string[cmd], bank); end end else begin // BL=8 if (ck_cntr - ck_read < read_latency + TCCD + 2 - write_latency) $display ("%m: at time %t ERROR: tRTW violation during %s to bank %d", $time, cmd_string[cmd], bank); end if (mpr_en) begin $display ("%m: at time %t ERROR: %s Failure. Multipurpose Register must be disabled.", $time, cmd_string[cmd]); if (STOP_ON_ERROR) $stop(0); end else if (!init_done) begin $display ("%m: at time %t ERROR: %s Failure. Initialization sequence is not complete.", $time, cmd_string[cmd]); if (STOP_ON_ERROR) $stop(0); end else if (!active_bank[bank]) begin if (check_strict_timing) $display ("%m: at time %t ERROR: %s Failure. Bank %d must be Activated.", $time, cmd_string[cmd], bank); if (STOP_ON_ERROR) $stop(0); end else if (auto_precharge_bank[bank]) begin $display ("%m: at time %t ERROR: %s Failure. Auto Precharge is scheduled to bank %d.", $time, cmd_string[cmd], bank); if (STOP_ON_ERROR) $stop(0); end else if (ck_cntr - ck_write < burst_length/2) begin $display ("%m: at time %t ERROR: %s Failure. Illegal burst interruption.", $time, cmd_string[cmd]); if (STOP_ON_ERROR) $stop(0); end else begin if (addr[AP]) begin auto_precharge_bank[bank] = 1'b1; write_precharge_bank[bank] = 1'b1; end col = {addr[BC-1:AP+1], addr[AP-1:0]}; // assume BC > AP if (col >= 1<<COL_BITS) begin $display ("%m: at time %t WARNING: col = %h does not exist. Maximum col = %h", $time, col, (1<<COL_BITS)-1); end if ((!addr[BC] && blotf) || (burst_length == 4)) begin // BL=4 col = col & -4; end else begin // BL=8 col = col & -8; end if (DEBUG) $display ("%m: at time %t INFO: %s bank %d col %h, auto precharge %d", $time, cmd_string[cmd], bank, col, addr[AP]); wr_pipeline[2*write_latency + 1] = 1; ba_pipeline[2*write_latency + 1] = bank; row_pipeline[2*write_latency + 1] = active_row[bank]; col_pipeline[2*write_latency + 1] = col; if ((!addr[BC] && blotf) || (burst_length == 4)) begin // BL=4 bl_pipeline[2*write_latency + 1] = 4; if (mpr_en && col%4) begin $display ("%m: at time %t WARNING: col[1:0] must be set to 2'b00 during a BL4 Multipurpose Register read", $time); end end else begin // BL=8 bl_pipeline[2*write_latency + 1] = 8; if (odt_in) begin ck_odth8 <= ck_cntr; end end for (j=0; j<(burst_length + 4); j=j+1) begin dyn_odt_pipeline[2*(write_latency - 2) + j] = 1'b1; // ODTLcnw = WL - 2, ODTLcwn = BL/2 + 2 end ck_bank_write[bank] <= ck_cntr; ck_group_write[bank[1]] <= ck_cntr; ck_write <= ck_cntr; end end READ : begin if (!dll_locked) $display ("%m: at time %t WARNING: tDLLK violation during %s.", $time, cmd_string[cmd]); if (mpr_en && (addr[1:0] != 2'b00)) begin $display ("%m: at time %t ERROR: %s Failure. addr[1:0] must be zero during Multipurpose Register Read.", $time, cmd_string[cmd]); if (STOP_ON_ERROR) $stop(0); end else if (!init_done) begin $display ("%m: at time %t ERROR: %s Failure. Initialization sequence is not complete.", $time, cmd_string[cmd]); if (STOP_ON_ERROR) $stop(0); end else if (!active_bank[bank] && !mpr_en) begin if (check_strict_timing) $display ("%m: at time %t ERROR: %s Failure. Bank %d must be Activated.", $time, cmd_string[cmd], bank); if (STOP_ON_ERROR) $stop(0); end else if (auto_precharge_bank[bank]) begin $display ("%m: at time %t ERROR: %s Failure. Auto Precharge is scheduled to bank %d.", $time, cmd_string[cmd], bank); if (STOP_ON_ERROR) $stop(0); end else if (ck_cntr - ck_read < burst_length/2) begin $display ("%m: at time %t ERROR: %s Failure. Illegal burst interruption.", $time, cmd_string[cmd]); if (STOP_ON_ERROR) $stop(0); end else begin if (addr[AP] && !mpr_en) begin auto_precharge_bank[bank] = 1'b1; read_precharge_bank[bank] = 1'b1; end col = {addr[BC-1:AP+1], addr[AP-1:0]}; // assume BC > AP if (col >= 1<<COL_BITS) begin $display ("%m: at time %t WARNING: col = %h does not exist. Maximum col = %h", $time, col, (1<<COL_BITS)-1); end if (DEBUG) $display ("%m: at time %t INFO: %s bank %d col %h, auto precharge %d", $time, cmd_string[cmd], bank, col, addr[AP]); rd_pipeline[2*read_latency - 1] = 1; ba_pipeline[2*read_latency - 1] = bank; row_pipeline[2*read_latency - 1] = active_row[bank]; col_pipeline[2*read_latency - 1] = col; if ((!addr[BC] && blotf) || (burst_length == 4)) begin // BL=4 bl_pipeline[2*read_latency - 1] = 4; if (mpr_en && col%4) begin $display ("%m: at time %t WARNING: col[1:0] must be set to 2'b00 during a BL4 Multipurpose Register read", $time); end end else begin // BL=8 bl_pipeline[2*read_latency - 1] = 8; if (mpr_en && col%8) begin $display ("%m: at time %t WARNING: col[2:0] must be set to 3'b000 during a BL8 Multipurpose Register read", $time); end end rd_bc = addr[BC]; ck_bank_read[bank] <= ck_cntr; ck_group_read[bank[1]] <= ck_cntr; ck_read <= ck_cntr; end end ZQ : begin if (mpr_en) begin $display ("%m: at time %t ERROR: %s Failure. Multipurpose Register must be disabled.", $time, cmd_string[cmd]); if (STOP_ON_ERROR) $stop(0); end else if (|active_bank) begin $display ("%m: at time %t ERROR: %s Failure. All banks must be Precharged.", $time, cmd_string[cmd]); if (STOP_ON_ERROR) $stop(0); end else begin if (DEBUG) $display ("%m: at time %t INFO: %s long = %d", $time, cmd_string[cmd], addr[AP]); if (addr[AP]) begin zq_set = 1; if (init_done) begin ck_zqoper <= ck_cntr; end else begin ck_zqinit <= ck_cntr; end end else begin ck_zqcs <= ck_cntr; end end end NOP: begin if (in_power_down) begin if (($time - tm_freq_change < TCKSRX) || (ck_cntr - ck_freq_change < TCKSRX_TCK)) $display ("%m: at time %t ERROR: tCKSRX violation during Power Down Exit", $time); if ($time - tm_cke_cmd > TPD_MAX) $display ("%m: at time %t ERROR: tPD maximum violation during Power Down Exit", $time); if (DEBUG) $display ("%m: at time %t INFO: Power Down Exit", $time); in_power_down = 0; if ((active_bank == 0) && low_power) begin // precharge power down with dll off if (ck_cntr - ck_odt < write_latency - 1) $display ("%m: at time %t WARNING: tANPD violation during Power Down Exit. Synchronous or asynchronous change in termination resistance is possible.", $time); tm_slow_exit_pd <= $time; ck_slow_exit_pd <= ck_cntr; end tm_power_down <= $time; ck_power_down <= ck_cntr; end if (in_self_refresh) begin if (($time - tm_freq_change < TCKSRX) || (ck_cntr - ck_freq_change < TCKSRX_TCK)) $display ("%m: at time %t ERROR: tCKSRX violation during Self Refresh Exit", $time); if (ck_cntr - ck_cke_cmd < TCKESR_TCK) $display ("%m: at time %t ERROR: tCKESR violation during Self Refresh Exit", $time); if ($time - tm_cke < TISXR) $display ("%m: at time %t ERROR: tISXR violation during Self Refresh Exit", $time); if (DEBUG) $display ("%m: at time %t INFO: Self Refresh Exit", $time); in_self_refresh = 0; ck_dll_reset <= ck_cntr; ck_self_refresh <= ck_cntr; tm_self_refresh <= $time; tm_refresh <= $time; end end endcase if ((prev_cke !== 1) && (cmd !== NOP)) begin $display ("%m: at time %t ERROR: NOP or Deselect is required when CKE goes active.", $time); end if (!init_done) begin case (init_step) 0 : begin if ($time - tm_rst_n < 500000000 && check_strict_timing) $display ("%m at time %t WARNING: 500 us is required after RST_N goes inactive before CKE goes active.", $time); tm_txpr <= $time; ck_txpr <= ck_cntr; init_step = init_step + 1; end 1 : if (dll_en) init_step = init_step + 1; 2 : begin if (&init_mode_reg && init_dll_reset && zq_set) begin if (DEBUG) $display ("%m: at time %t INFO: Initialization Sequence is complete", $time); init_done = 1; end end endcase end end else if (prev_cke) begin if ((!init_done) && (init_step > 1)) begin $display ("%m: at time %t ERROR: CKE must remain active until the initialization sequence is complete.", $time); if (STOP_ON_ERROR) $stop(0); end case (cmd) REFRESH : begin if ($time - tm_txpr < TXPR) $display ("%m: at time %t ERROR: tXPR violation during %s", $time, cmd_string[SELF_REF]); for (j=0; j<=SELF_REF; j=j+1) begin chk_err(DIFF_BANK, bank, j, SELF_REF); end if (mpr_en) begin $display ("%m: at time %t ERROR: Self Refresh Failure. Multipurpose Register must be disabled.", $time); if (STOP_ON_ERROR) $stop(0); end else if (|active_bank) begin $display ("%m: at time %t ERROR: Self Refresh Failure. All banks must be Precharged.", $time); if (STOP_ON_ERROR) $stop(0); end else if (odt_state) begin $display ("%m: at time %t ERROR: Self Refresh Failure. ODT must be off prior to entering Self Refresh", $time); if (STOP_ON_ERROR) $stop(0); end else if (!init_done) begin $display ("%m: at time %t ERROR: Self Refresh Failure. Initialization sequence is not complete.", $time); if (STOP_ON_ERROR) $stop(0); end else begin if (DEBUG) $display ("%m: at time %t INFO: Self Refresh Enter", $time); if (feature_pasr) // Partial Array Self Refresh case (pasr) 3'b000 : ;//keep Bank 0-7 3'b001 : begin if (DEBUG) $display("%m: at time %t INFO: Banks 4-7 will be lost due to Partial Array Self Refresh", $time); erase_banks(8'hF0); end 3'b010 : begin if (DEBUG) $display("%m: at time %t INFO: Banks 2-7 will be lost due to Partial Array Self Refresh", $time); erase_banks(8'hFC); end 3'b011 : begin if (DEBUG) $display("%m: at time %t INFO: Banks 1-7 will be lost due to Partial Array Self Refresh", $time); erase_banks(8'hFE); end 3'b100 : begin if (DEBUG) $display("%m: at time %t INFO: Banks 0-1 will be lost due to Partial Array Self Refresh", $time); erase_banks(8'h03); end 3'b101 : begin if (DEBUG) $display("%m: at time %t INFO: Banks 0-3 will be lost due to Partial Array Self Refresh", $time); erase_banks(8'h0F); end 3'b110 : begin if (DEBUG) $display("%m: at time %t INFO: Banks 0-5 will be lost due to Partial Array Self Refresh", $time); erase_banks(8'h3F); end 3'b111 : begin if (DEBUG) $display("%m: at time %t INFO: Banks 0-6 will be lost due to Partial Array Self Refresh", $time); erase_banks(8'h7F); end endcase in_self_refresh = 1; dll_locked = 0; end end NOP : begin // entering precharge power down with dll off and tANPD has not been satisfied if (low_power && (active_bank == 0) && |odt_pipeline) $display ("%m: at time %t WARNING: tANPD violation during %s. Synchronous or asynchronous change in termination resistance is possible.", $time, cmd_string[PWR_DOWN]); if ($time - tm_txpr < TXPR) $display ("%m: at time %t ERROR: tXPR violation during %s", $time, cmd_string[PWR_DOWN]); for (j=0; j<=SELF_REF; j=j+1) begin chk_err(DIFF_BANK, bank, j, PWR_DOWN); end if (mpr_en) begin $display ("%m: at time %t ERROR: Power Down Failure. Multipurpose Register must be disabled.", $time); if (STOP_ON_ERROR) $stop(0); end else if (!init_done) begin $display ("%m: at time %t ERROR: Power Down Failure. Initialization sequence is not complete.", $time); if (STOP_ON_ERROR) $stop(0); end else begin if (DEBUG) begin if (|active_bank) begin $display ("%m: at time %t INFO: Active Power Down Enter", $time); end else begin $display ("%m: at time %t INFO: Precharge Power Down Enter", $time); end end in_power_down = 1; end end default : begin $display ("%m: at time %t ERROR: NOP, Deselect, or Refresh is required when CKE goes inactive.", $time); end endcase end else if (in_self_refresh || in_power_down) begin if ((ck_cntr - ck_cke_cmd <= TCPDED) && (cmd !== NOP)) $display ("%m: at time %t ERROR: tCPDED violation during Power Down or Self Refresh Entry. NOP or Deselect is required.", $time); end prev_cke = cke; end endtask task data_task; reg [BA_BITS-1:0] bank; reg [ROW_BITS-1:0] row; reg [COL_BITS-1:0] col; integer i; integer j; begin if (diff_ck) begin for (i=0; i<32; i=i+1) begin if (dq_in_valid && dll_locked && ($time - tm_dqs_neg[i] < $rtoi(TDSS*tck_avg))) $display ("%m: at time %t ERROR: tDSS violation on %s bit %d", $time, dqs_string[i/16], i%16); if (check_write_dqs_high[i]) $display ("%m: at time %t ERROR: %s bit %d latching edge required during the preceding clock period.", $time, dqs_string[i/16], i%16); end check_write_dqs_high <= 0; end else begin for (i=0; i<32; i=i+1) begin if (dll_locked && dq_in_valid) begin tm_tdqss = abs_value(1.0*tm_ck_pos - tm_dqss_pos[i]); if ((tm_tdqss < tck_avg/2.0) && (tm_tdqss > TDQSS*tck_avg)) $display ("%m: at time %t ERROR: tDQSS violation on %s bit %d", $time, dqs_string[i/16], i%16); end if (check_write_dqs_low[i]) $display ("%m: at time %t ERROR: %s bit %d latching edge required during the preceding clock period", $time, dqs_string[i/16], i%16); end check_write_preamble <= 0; check_write_postamble <= 0; check_write_dqs_low <= 0; end if (wr_pipeline[0] || rd_pipeline[0]) begin bank = ba_pipeline[0]; row = row_pipeline[0]; col = col_pipeline[0]; burst_cntr = 0; memory_read(bank, row, col, memory_data); end // burst counter if (burst_cntr < burst_length) begin burst_position = col ^ burst_cntr; if (!burst_order) begin burst_position[BO_BITS-1:0] = col + burst_cntr; end burst_cntr = burst_cntr + 1; end // write dqs counter if (wr_pipeline[WDQS_PRE + 1]) begin wdqs_cntr = WDQS_PRE + bl_pipeline[WDQS_PRE + 1] + WDQS_PST - 1; end // write dqs if ((wr_pipeline[2]) && (wdq_cntr == 0)) begin //write preamble check_write_preamble <= ({DQS_BITS{1'b1}}<<16) | {DQS_BITS{1'b1}}; end if (wdqs_cntr > 1) begin // write data if ((wdqs_cntr - WDQS_PST)%2) begin check_write_dqs_high <= ({DQS_BITS{1'b1}}<<16) | {DQS_BITS{1'b1}}; end else begin check_write_dqs_low <= ({DQS_BITS{1'b1}}<<16) | {DQS_BITS{1'b1}}; end end if (wdqs_cntr == WDQS_PST) begin // write postamble check_write_postamble <= ({DQS_BITS{1'b1}}<<16) | {DQS_BITS{1'b1}}; end if (wdqs_cntr > 0) begin wdqs_cntr = wdqs_cntr - 1; end // write dq if (dq_in_valid) begin // write data bit_mask = 0; if (diff_ck) begin for (i=0; i<DM_BITS; i=i+1) begin bit_mask = bit_mask | ({`DQ_PER_DQS{~dm_in_neg[i]}}<<(burst_position*DQ_BITS + i*`DQ_PER_DQS)); end memory_data = (dq_in_neg<<(burst_position*DQ_BITS) & bit_mask) | (memory_data & ~bit_mask); end else begin for (i=0; i<DM_BITS; i=i+1) begin bit_mask = bit_mask | ({`DQ_PER_DQS{~dm_in_pos[i]}}<<(burst_position*DQ_BITS + i*`DQ_PER_DQS)); end memory_data = (dq_in_pos<<(burst_position*DQ_BITS) & bit_mask) | (memory_data & ~bit_mask); end dq_temp = memory_data>>(burst_position*DQ_BITS); if (DEBUG) $display ("%m: at time %t INFO: WRITE @ DQS= bank = %h row = %h col = %h data = %h",$time, bank, row, (-1*BL_MAX & col) + burst_position, dq_temp); if (burst_cntr%BL_MIN == 0) begin memory_write(bank, row, col, memory_data); end end if (wr_pipeline[1]) begin wdq_cntr = bl_pipeline[1]; end if (wdq_cntr > 0) begin wdq_cntr = wdq_cntr - 1; dq_in_valid = 1'b1; end else begin dq_in_valid = 1'b0; dqs_in_valid <= 1'b0; for (i=0; i<31; i=i+1) begin wdqs_pos_cntr[i] <= 0; end end if (wr_pipeline[0]) begin b2b_write <= 1'b0; end if (wr_pipeline[2]) begin if (dqs_in_valid) begin b2b_write <= 1'b1; end dqs_in_valid <= 1'b1; wr_burst_length = bl_pipeline[2]; end // read dqs enable counter if (rd_pipeline[RDQSEN_PRE]) begin rdqsen_cntr = RDQSEN_PRE + bl_pipeline[RDQSEN_PRE] + RDQSEN_PST - 1; end if (rdqsen_cntr > 0) begin rdqsen_cntr = rdqsen_cntr - 1; dqs_out_en = 1'b1; end else begin dqs_out_en = 1'b0; end // read dqs counter if (rd_pipeline[RDQS_PRE]) begin rdqs_cntr = RDQS_PRE + bl_pipeline[RDQS_PRE] + RDQS_PST - 1; end // read dqs if (((rd_pipeline>>1 & {RDQS_PRE{1'b1}}) > 0) && (rdq_cntr == 0)) begin //read preamble dqs_out = 1'b0; end else if (rdqs_cntr > RDQS_PST) begin // read data dqs_out = rdqs_cntr - RDQS_PST; end else if (rdqs_cntr > 0) begin // read postamble dqs_out = 1'b0; end else begin dqs_out = 1'b1; end if (rdqs_cntr > 0) begin rdqs_cntr = rdqs_cntr - 1; end // read dq enable counter if (rd_pipeline[RDQEN_PRE]) begin rdqen_cntr = RDQEN_PRE + bl_pipeline[RDQEN_PRE] + RDQEN_PST; end if (rdqen_cntr > 0) begin rdqen_cntr = rdqen_cntr - 1; dq_out_en = 1'b1; end else begin dq_out_en = 1'b0; end // read dq if (rd_pipeline[0]) begin rdq_cntr = bl_pipeline[0]; end if (rdq_cntr > 0) begin // read data if (mpr_en) begin `ifdef MPR_DQ0 // DQ0 output MPR data, other DQ low if (mpr_select == 2'b00) begin // Calibration Pattern dq_temp = {DQS_BITS{{`DQ_PER_DQS-1{1'b0}}, calibration_pattern[burst_position]}}; end else if (odts_readout && (mpr_select == 2'b11)) begin // Temp Sensor (ODTS) dq_temp = {DQS_BITS{{`DQ_PER_DQS-1{1'b0}}, temp_sensor[burst_position]}}; end else begin // Reserved dq_temp = {DQS_BITS{{`DQ_PER_DQS-1{1'b0}}, 1'bx}}; end `else // all DQ output MPR data if (mpr_select == 2'b00) begin // Calibration Pattern dq_temp = {DQS_BITS{{`DQ_PER_DQS{calibration_pattern[burst_position]}}}}; end else if (odts_readout && (mpr_select == 2'b11)) begin // Temp Sensor (ODTS) dq_temp = {DQS_BITS{{`DQ_PER_DQS{temp_sensor[burst_position]}}}}; end else begin // Reserved dq_temp = {DQS_BITS{{`DQ_PER_DQS{1'bx}}}}; end `endif if (DEBUG) $display ("%m: at time %t READ @ DQS MultiPurpose Register %d, col = %d, data = %b", $time, mpr_select, burst_position, dq_temp[0]); end else begin dq_temp = memory_data>>(burst_position*DQ_BITS); if (DEBUG) $display ("%m: at time %t INFO: READ @ DQS= bank = %h row = %h col = %h data = %h",$time, bank, row, (-1*BL_MAX & col) + burst_position, dq_temp); end dq_out = dq_temp; rdq_cntr = rdq_cntr - 1; end else begin dq_out = {DQ_BITS{1'b1}}; end // delay signals prior to output if (RANDOM_OUT_DELAY && (dqs_out_en || (|dqs_out_en_dly) || dq_out_en || (|dq_out_en_dly))) begin for (i=0; i<DQS_BITS; i=i+1) begin // DQSCK requirements // 1.) less than tDQSCK // 2.) greater than -tDQSCK // 3.) cannot change more than tQH + tDQSQ from previous DQS edge dqsck_max = TDQSCK; if (dqsck_max > dqsck[i] + TQH*tck_avg + TDQSQ) begin dqsck_max = dqsck[i] + TQH*tck_avg + TDQSQ; end dqsck_min = -1*TDQSCK; if (dqsck_min < dqsck[i] - TQH*tck_avg - TDQSQ) begin dqsck_min = dqsck[i] - TQH*tck_avg - TDQSQ; end // DQSQ requirements // 1.) less than tDQSQ // 2.) greater than 0 // 3.) greater than tQH from the previous DQS edge dqsq_min = 0; if (dqsq_min < dqsck[i] - TQH*tck_avg) begin dqsq_min = dqsck[i] - TQH*tck_avg; end if (dqsck_min == dqsck_max) begin dqsck[i] = dqsck_min; end else begin dqsck[i] = $dist_uniform(seed, dqsck_min, dqsck_max); end dqsq_max = TDQSQ + dqsck[i]; dqs_out_en_dly[i] <= #(tck_avg/2) dqs_out_en; dqs_out_dly[i] <= #(tck_avg/2 + dqsck[i]) dqs_out; if (!write_levelization) begin for (j=0; j<`DQ_PER_DQS; j=j+1) begin dq_out_en_dly[i*`DQ_PER_DQS + j] <= #(tck_avg/2) dq_out_en; if (dqsq_min == dqsq_max) begin dq_out_dly [i*`DQ_PER_DQS + j] <= #(tck_avg/2 + dqsq_min) dq_out[i*`DQ_PER_DQS + j]; end else begin dq_out_dly [i*`DQ_PER_DQS + j] <= #(tck_avg/2 + $dist_uniform(seed, dqsq_min, dqsq_max)) dq_out[i*`DQ_PER_DQS + j]; end end end end end else begin out_delay = tck_avg/2; dqs_out_en_dly <= #(out_delay) {DQS_BITS{dqs_out_en}}; dqs_out_dly <= #(out_delay) {DQS_BITS{dqs_out }}; if (write_levelization !== 1'b1) begin dq_out_en_dly <= #(out_delay) {DQ_BITS {dq_out_en }}; dq_out_dly <= #(out_delay) {DQ_BITS {dq_out }}; end end end endtask always @ (posedge rst_n_in) begin : reset integer i; if (rst_n_in) begin if ($time < 200000000 && check_strict_timing) $display ("%m at time %t WARNING: 200 us is required before RST_N goes inactive.", $time); if (cke_in !== 1'b0) $display ("%m: at time %t ERROR: CKE must be inactive when RST_N goes inactive.", $time); if ($time - tm_cke < 10000) $display ("%m: at time %t ERROR: CKE must be maintained inactive for 10 ns before RST_N goes inactive.", $time); // clear memory `ifdef MAX_MEM // verification group does not erase memory // for (banki = 0; banki < `BANKS; banki = banki + 1) begin // $fclose(memfd[banki]); // memfd[banki] = open_bank_file(banki); // end `else memory_used <= 0; //erase memory `endif end end always @(negedge rst_n_in or posedge diff_ck or negedge diff_ck) begin : main integer i; if (!rst_n_in) begin reset_task; end else begin if (!in_self_refresh && (diff_ck !== 1'b0) && (diff_ck !== 1'b1)) $display ("%m: at time %t ERROR: CK and CK_N are not allowed to go to an unknown state.", $time); data_task; // Clock Frequency Change is legal: // 1.) During Self Refresh // 2.) During Precharge Power Down (DLL on or off) if (in_self_refresh || (in_power_down && (active_bank == 0))) begin if (diff_ck) begin tjit_per_rtime = $time - tm_ck_pos - tck_avg; end else begin tjit_per_rtime = $time - tm_ck_neg - tck_avg; end if (dll_locked && (abs_value(tjit_per_rtime) > TJIT_PER)) begin if ((tm_ck_pos - tm_cke_cmd < TCKSRE) || (ck_cntr - ck_cke_cmd < TCKSRE_TCK)) $display ("%m: at time %t ERROR: tCKSRE violation during Self Refresh or Precharge Power Down Entry", $time); if (odt_state) begin $display ("%m: at time %t ERROR: Clock Frequency Change Failure. ODT must be off prior to Clock Frequency Change.", $time); if (STOP_ON_ERROR) $stop(0); end else begin if (DEBUG) $display ("%m: at time %t INFO: Clock Frequency Change detected. DLL Reset is Required.", $time); tm_freq_change <= $time; ck_freq_change <= ck_cntr; dll_locked = 0; end end end if (diff_ck) begin // check setup of command signals if ($time > TIS) begin if ($time - tm_cke < TIS) $display ("%m: at time %t ERROR: tIS violation on CKE by %t", $time, tm_cke + TIS - $time); if (cke_in) begin for (i=0; i<22; i=i+1) begin if ($time - tm_cmd_addr[i] < TIS) $display ("%m: at time %t ERROR: tIS violation on %s by %t", $time, cmd_addr_string[i], tm_cmd_addr[i] + TIS - $time); end end end // update current state if (dll_locked) begin if (mr_chk == 0) begin mr_chk = 1; end else if (init_mode_reg[0] && (mr_chk == 1)) begin // check CL value against the clock frequency if (cas_latency*tck_avg < CL_TIME && check_strict_timing) $display ("%m: at time %t ERROR: CAS Latency = %d is illegal @tCK(avg) = %f", $time, cas_latency, tck_avg); // check WR value against the clock frequency if (ceil(write_recovery*tck_avg) < TWR) $display ("%m: at time %t ERROR: Write Recovery = %d is illegal @tCK(avg) = %f", $time, write_recovery, tck_avg); // check the CWL value against the clock frequency if (check_strict_timing) begin case (cas_write_latency) 5 : if (tck_avg < 2500.0) $display ("%m: at time %t ERROR: CWL = %d is illegal @tCK(avg) = %f", $time, cas_write_latency, tck_avg); 6 : if ((tck_avg < 1875.0) || (tck_avg >= 2500.0)) $display ("%m: at time %t ERROR: CWL = %d is illegal @tCK(avg) = %f", $time, cas_write_latency, tck_avg); 7 : if ((tck_avg < 1500.0) || (tck_avg >= 1875.0)) $display ("%m: at time %t ERROR: CWL = %d is illegal @tCK(avg) = %f", $time, cas_write_latency, tck_avg); 8 : if ((tck_avg < 1250.0) || (tck_avg >= 1500.0)) $display ("%m: at time %t ERROR: CWL = %d is illegal @tCK(avg) = %f", $time, cas_write_latency, tck_avg); 9 : if ((tck_avg < 15e3/14) || (tck_avg >= 1250.0)) $display ("%m: at time %t ERROR: CWL = %d is illegal @tCK(avg) = %f", $time, cas_write_latency, tck_avg); 10: if ((tck_avg < 937.5) || (tck_avg >= 15e3/14)) $display ("%m: at time %t ERROR: CWL = %d is illegal @tCK(avg) = %f", $time, cas_write_latency, tck_avg); default : $display ("%m: at time %t ERROR: CWL = %d is illegal @tCK(avg) = %f", $time, cas_write_latency, tck_avg); endcase // check the CL value against the clock frequency if (!valid_cl(cas_latency, cas_write_latency)) $display ("%m: at time %t ERROR: CAS Latency = %d is not valid when CAS Write Latency = %d", $time, cas_latency, cas_write_latency); end mr_chk = 2; end end else if (!in_self_refresh) begin mr_chk = 0; if (ck_cntr - ck_dll_reset == TDLLK) begin dll_locked = 1; end end if (|auto_precharge_bank) begin for (i=0; i<`BANKS; i=i+1) begin // Write with Auto Precharge Calculation // 1. Meet minimum tRAS requirement // 2. Write Latency PLUS BL/2 cycles PLUS WR after Write command if (write_precharge_bank[i]) begin if ($time - tm_bank_activate[i] >= TRAS_MIN) begin if (ck_cntr - ck_bank_write[i] >= write_latency + burst_length/2 + write_recovery) begin if (DEBUG) $display ("%m: at time %t INFO: Auto Precharge bank %d", $time, i); write_precharge_bank[i] = 0; active_bank[i] = 0; auto_precharge_bank[i] = 0; tm_bank_precharge[i] = $time; tm_precharge = $time; ck_precharge = ck_cntr; end end end // Read with Auto Precharge Calculation // 1. Meet minimum tRAS requirement // 2. Additive Latency plus 4 cycles after Read command // 3. tRTP after the last 8-bit prefetch if (read_precharge_bank[i]) begin if (($time - tm_bank_activate[i] >= TRAS_MIN) && (ck_cntr - ck_bank_read[i] >= additive_latency + TRTP_TCK)) begin read_precharge_bank[i] = 0; // In case the internal precharge is pushed out by tRTP, tRP starts at the point where // the internal precharge happens (not at the next rising clock edge after this event). if ($time - tm_bank_read_end[i] < TRTP) begin if (DEBUG) $display ("%m: at time %t INFO: Auto Precharge bank %d", tm_bank_read_end[i] + TRTP, i); active_bank[i] <= #(tm_bank_read_end[i] + TRTP - $time) 0; auto_precharge_bank[i] <= #(tm_bank_read_end[i] + TRTP - $time) 0; tm_bank_precharge[i] <= #(tm_bank_read_end[i] + TRTP - $time) tm_bank_read_end[i] + TRTP; tm_precharge <= #(tm_bank_read_end[i] + TRTP - $time) tm_bank_read_end[i] + TRTP; ck_precharge = ck_cntr; end else begin if (DEBUG) $display ("%m: at time %t INFO: Auto Precharge bank %d", $time, i); active_bank[i] = 0; auto_precharge_bank[i] = 0; tm_bank_precharge[i] = $time; tm_precharge = $time; ck_precharge = ck_cntr; end end end end end // respond to incoming command if (cke_in ^ prev_cke) begin tm_cke_cmd <= $time; ck_cke_cmd <= ck_cntr; end cmd_task(cke_in, cmd_n_in, ba_in, addr_in); if ((cmd_n_in == WRITE) || (cmd_n_in == READ)) begin al_pipeline[2*additive_latency] = 1'b1; end if (al_pipeline[0]) begin // check tRCD after additive latency if ((rd_pipeline[2*cas_latency - 1]) && ($time - tm_bank_activate[ba_pipeline[2*cas_latency - 1]] < TRCD)) $display ("%m: at time %t ERROR: tRCD violation during %s", $time, cmd_string[READ]); if ((wr_pipeline[2*cas_write_latency + 1]) && ($time - tm_bank_activate[ba_pipeline[2*cas_write_latency + 1]] < TRCD)) $display ("%m: at time %t ERROR: tRCD violation during %s", $time, cmd_string[WRITE]); // check tWTR after additive latency if (rd_pipeline[2*cas_latency - 1]) begin //{ if (truebl4) begin //{ i = ba_pipeline[2*cas_latency - 1]; if ($time - tm_group_write_end[i[1]] < TWTR) $display ("%m: at time %t ERROR: tWTR violation during %s", $time, cmd_string[READ]); if ($time - tm_write_end < TWTR_DG) $display ("%m: at time %t ERROR: tWTR_DG violation during %s", $time, cmd_string[READ]); end else begin if ($time - tm_write_end < TWTR) $display ("%m: at time %t ERROR: tWTR violation during %s", $time, cmd_string[READ]); end end end if (rd_pipeline) begin if (rd_pipeline[2*cas_latency - 1]) begin tm_bank_read_end[ba_pipeline[2*cas_latency - 1]] <= $time; end end for (i=0; i<`BANKS; i=i+1) begin if ((ck_cntr - ck_bank_write[i] > write_latency) && (ck_cntr - ck_bank_write[i] <= write_latency + burst_length/2)) begin tm_bank_write_end[i] <= $time; tm_group_write_end[i[1]] <= $time; tm_write_end <= $time; end end // clk pin is disabled during self refresh if (!in_self_refresh && tm_ck_pos ) begin tjit_cc_time = $time - tm_ck_pos - tck_i; tck_i = $time - tm_ck_pos; tck_avg = tck_avg - tck_sample[ck_cntr%TDLLK]/$itor(TDLLK); tck_avg = tck_avg + tck_i/$itor(TDLLK); tck_sample[ck_cntr%TDLLK] = tck_i; tjit_per_rtime = tck_i - tck_avg; if (dll_locked && check_strict_timing) begin // check accumulated error terr_nper_rtime = 0; for (i=0; i<12; i=i+1) begin terr_nper_rtime = terr_nper_rtime + tck_sample[i] - tck_avg; terr_nper_rtime = abs_value(terr_nper_rtime); case (i) 0 :; 1 : if (terr_nper_rtime - TERR_2PER >= 1.0) $display ("%m: at time %t ERROR: tERR(2per) violation by %f ps.", $time, terr_nper_rtime - TERR_2PER); 2 : if (terr_nper_rtime - TERR_3PER >= 1.0) $display ("%m: at time %t ERROR: tERR(3per) violation by %f ps.", $time, terr_nper_rtime - TERR_3PER); 3 : if (terr_nper_rtime - TERR_4PER >= 1.0) $display ("%m: at time %t ERROR: tERR(4per) violation by %f ps.", $time, terr_nper_rtime - TERR_4PER); 4 : if (terr_nper_rtime - TERR_5PER >= 1.0) $display ("%m: at time %t ERROR: tERR(5per) violation by %f ps.", $time, terr_nper_rtime - TERR_5PER); 5 : if (terr_nper_rtime - TERR_6PER >= 1.0) $display ("%m: at time %t ERROR: tERR(6per) violation by %f ps.", $time, terr_nper_rtime - TERR_6PER); 6 : if (terr_nper_rtime - TERR_7PER >= 1.0) $display ("%m: at time %t ERROR: tERR(7per) violation by %f ps.", $time, terr_nper_rtime - TERR_7PER); 7 : if (terr_nper_rtime - TERR_8PER >= 1.0) $display ("%m: at time %t ERROR: tERR(8per) violation by %f ps.", $time, terr_nper_rtime - TERR_8PER); 8 : if (terr_nper_rtime - TERR_9PER >= 1.0) $display ("%m: at time %t ERROR: tERR(9per) violation by %f ps.", $time, terr_nper_rtime - TERR_9PER); 9 : if (terr_nper_rtime - TERR_10PER >= 1.0) $display ("%m: at time %t ERROR: tERR(10per) violation by %f ps.", $time, terr_nper_rtime - TERR_10PER); 10 : if (terr_nper_rtime - TERR_11PER >= 1.0) $display ("%m: at time %t ERROR: tERR(11per) violation by %f ps.", $time, terr_nper_rtime - TERR_11PER); 11 : if (terr_nper_rtime - TERR_12PER >= 1.0) $display ("%m: at time %t ERROR: tERR(12per) violation by %f ps.", $time, terr_nper_rtime - TERR_12PER); endcase end // check tCK min/max/jitter if (abs_value(tjit_per_rtime) - TJIT_PER >= 1.0) $display ("%m: at time %t ERROR: tJIT(per) violation by %f ps.", $time, abs_value(tjit_per_rtime) - TJIT_PER); if (abs_value(tjit_cc_time) - TJIT_CC >= 1.0) $display ("%m: at time %t ERROR: tJIT(cc) violation by %f ps.", $time, abs_value(tjit_cc_time) - TJIT_CC); if (TCK_MIN - tck_avg >= 1.0) $display ("%m: at time %t ERROR: tCK(avg) minimum violation by %f ps.", $time, TCK_MIN - tck_avg); if (tck_avg - TCK_MAX >= 1.0) $display ("%m: at time %t ERROR: tCK(avg) maximum violation by %f ps.", $time, tck_avg - TCK_MAX); // check tCL if (tm_ck_neg - $time < TCL_ABS_MIN*tck_avg) $display ("%m: at time %t ERROR: tCL(abs) minimum violation on CLK by %t", $time, TCL_ABS_MIN*tck_avg - tm_ck_neg + $time); if (tcl_avg < TCL_AVG_MIN*tck_avg) $display ("%m: at time %t ERROR: tCL(avg) minimum violation on CLK by %t", $time, TCL_AVG_MIN*tck_avg - tcl_avg); if (tcl_avg > TCL_AVG_MAX*tck_avg) $display ("%m: at time %t ERROR: tCL(avg) maximum violation on CLK by %t", $time, tcl_avg - TCL_AVG_MAX*tck_avg); end // calculate the tch avg jitter tch_avg = tch_avg - tch_sample[ck_cntr%TDLLK]/$itor(TDLLK); tch_avg = tch_avg + tch_i/$itor(TDLLK); tch_sample[ck_cntr%TDLLK] = tch_i; tjit_ch_rtime = tch_i - tch_avg; duty_cycle = tch_avg/tck_avg; // update timers/counters tcl_i <= $time - tm_ck_neg; end prev_odt <= odt_in; // update timers/counters ck_cntr <= ck_cntr + 1; tm_ck_pos = $time; end else begin // clk pin is disabled during self refresh if (!in_self_refresh) begin if (dll_locked && check_strict_timing) begin if ($time - tm_ck_pos < TCH_ABS_MIN*tck_avg) $display ("%m: at time %t ERROR: tCH(abs) minimum violation on CLK by %t", $time, TCH_ABS_MIN*tck_avg - $time + tm_ck_pos); if (tch_avg < TCH_AVG_MIN*tck_avg) $display ("%m: at time %t ERROR: tCH(avg) minimum violation on CLK by %t", $time, TCH_AVG_MIN*tck_avg - tch_avg); if (tch_avg > TCH_AVG_MAX*tck_avg) $display ("%m: at time %t ERROR: tCH(avg) maximum violation on CLK by %t", $time, tch_avg - TCH_AVG_MAX*tck_avg); end // calculate the tcl avg jitter tcl_avg = tcl_avg - tcl_sample[ck_cntr%TDLLK]/$itor(TDLLK); tcl_avg = tcl_avg + tcl_i/$itor(TDLLK); tcl_sample[ck_cntr%TDLLK] = tcl_i; // update timers/counters tch_i <= $time - tm_ck_pos; end tm_ck_neg = $time; end // on die termination if (odt_en || dyn_odt_en) begin // odt pin is disabled during self refresh if (!in_self_refresh && diff_ck) begin if ($time - tm_odt < TIS) $display ("%m: at time %t ERROR: tIS violation on ODT by %t", $time, tm_odt + TIS - $time); if (prev_odt ^ odt_in) begin if (!dll_locked) $display ("%m: at time %t WARNING: tDLLK violation during ODT transition.", $time); if (($time - tm_load_mode < TMOD) || (ck_cntr - ck_load_mode < TMOD_TCK)) $display ("%m: at time %t ERROR: tMOD violation during ODT transition", $time); if (ck_cntr - ck_zqinit < TZQINIT) $display ("%m: at time %t ERROR: TZQinit violation during ODT transition", $time); if (ck_cntr - ck_zqoper < TZQOPER) $display ("%m: at time %t ERROR: TZQoper violation during ODT transition", $time); if (ck_cntr - ck_zqcs < TZQCS) $display ("%m: at time %t ERROR: tZQcs violation during ODT transition", $time); // if (($time - tm_slow_exit_pd < TXPDLL) || (ck_cntr - ck_slow_exit_pd < TXPDLL_TCK)) // $display ("%m: at time %t ERROR: tXPDLL violation during ODT transition", $time); if (ck_cntr - ck_self_refresh < TXSDLL) $display ("%m: at time %t ERROR: tXSDLL violation during ODT transition", $time); if (in_self_refresh) $display ("%m: at time %t ERROR: Illegal ODT transition during Self Refresh.", $time); if (!odt_in && (ck_cntr - ck_odt < ODTH4)) $display ("%m: at time %t ERROR: ODTH4 violation during ODT transition", $time); if (!odt_in && (ck_cntr - ck_odth8 < ODTH8)) $display ("%m: at time %t ERROR: ODTH8 violation during ODT transition", $time); if (($time - tm_slow_exit_pd < TXPDLL) || (ck_cntr - ck_slow_exit_pd < TXPDLL_TCK)) $display ("%m: at time %t WARNING: tXPDLL during ODT transition. Synchronous or asynchronous change in termination resistance is possible.", $time); // async ODT mode applies: // 1.) during precharge power down with DLL off // 2.) if tANPD has not been satisfied // 3.) until tXPDLL has been satisfied if ((in_power_down && low_power && (active_bank == 0)) || ($time - tm_slow_exit_pd < TXPDLL) || (ck_cntr - ck_slow_exit_pd < TXPDLL_TCK)) begin odt_state = odt_in; if (DEBUG && odt_en) $display ("%m: at time %t INFO: Async On Die Termination Rtt_NOM = %d Ohm", $time, {32{odt_state}} & get_rtt_nom(odt_rtt_nom)); if (odt_state) begin odt_state_dly <= #(TAONPD) odt_state; end else begin odt_state_dly <= #(TAOFPD) odt_state; end // sync ODT mode applies: // 1.) during normal operation // 2.) during active power down // 3.) during precharge power down with DLL on end else begin odt_pipeline[2*(write_latency - 2)] = 1'b1; // ODTLon, ODTLoff end ck_odt <= ck_cntr; end end if (odt_pipeline[0]) begin odt_state = ~odt_state; if (DEBUG && odt_en) $display ("%m: at time %t INFO: Sync On Die Termination Rtt_NOM = %d Ohm", $time, {32{odt_state}} & get_rtt_nom(odt_rtt_nom)); if (odt_state) begin odt_state_dly <= #(TAON) odt_state; end else begin odt_state_dly <= #(TAOF*tck_avg) odt_state; end end if (rd_pipeline[RDQSEN_PRE]) begin odt_cntr = 1 + RDQSEN_PRE + bl_pipeline[RDQSEN_PRE] + RDQSEN_PST - 1; end if (odt_cntr > 0) begin if (odt_state) begin $display ("%m: at time %t ERROR: On Die Termination must be OFF during Read data transfer.", $time); end odt_cntr = odt_cntr - 1; end if (dyn_odt_en && odt_state) begin if (DEBUG && (dyn_odt_state ^ dyn_odt_pipeline[0])) $display ("%m: at time %t INFO: Sync On Die Termination Rtt_WR = %d Ohm", $time, {32{dyn_odt_pipeline[0]}} & get_rtt_wr(odt_rtt_wr)); dyn_odt_state = dyn_odt_pipeline[0]; end dyn_odt_state_dly <= #(TADC*tck_avg) dyn_odt_state; end if (cke_in && write_levelization) begin for (i=0; i<DQS_BITS; i=i+1) begin if ($time - tm_dqs_pos[i] < TWLH) $display ("%m: at time %t WARNING: tWLH violation on DQS bit %d positive edge. Indeterminate CK capture is possible.", $time, i); end end // shift pipelines if (|wr_pipeline || |rd_pipeline || |al_pipeline) begin al_pipeline = al_pipeline>>1; wr_pipeline = wr_pipeline>>1; rd_pipeline = rd_pipeline>>1; for (i=0; i<`MAX_PIPE; i=i+1) begin bl_pipeline[i] = bl_pipeline[i+1]; ba_pipeline[i] = ba_pipeline[i+1]; row_pipeline[i] = row_pipeline[i+1]; col_pipeline[i] = col_pipeline[i+1]; end end if (|odt_pipeline || |dyn_odt_pipeline) begin odt_pipeline = odt_pipeline>>1; dyn_odt_pipeline = dyn_odt_pipeline>>1; end end end // receiver(s) task dqs_even_receiver; input [3:0] i; reg [63:0] bit_mask; begin bit_mask = {`DQ_PER_DQS{1'b1}}<<(i*`DQ_PER_DQS); if (dqs_even[i]) begin if (tdqs_en) begin // tdqs disables dm dm_in_pos[i] = 1'b0; end else begin dm_in_pos[i] = dm_in[i]; end dq_in_pos = (dq_in & bit_mask) | (dq_in_pos & ~bit_mask); end end endtask always @(posedge dqs_even[ 0]) dqs_even_receiver( 0); always @(posedge dqs_even[ 1]) dqs_even_receiver( 1); always @(posedge dqs_even[ 2]) dqs_even_receiver( 2); always @(posedge dqs_even[ 3]) dqs_even_receiver( 3); always @(posedge dqs_even[ 4]) dqs_even_receiver( 4); always @(posedge dqs_even[ 5]) dqs_even_receiver( 5); always @(posedge dqs_even[ 6]) dqs_even_receiver( 6); always @(posedge dqs_even[ 7]) dqs_even_receiver( 7); always @(posedge dqs_even[ 8]) dqs_even_receiver( 8); always @(posedge dqs_even[ 9]) dqs_even_receiver( 9); always @(posedge dqs_even[10]) dqs_even_receiver(10); always @(posedge dqs_even[11]) dqs_even_receiver(11); always @(posedge dqs_even[12]) dqs_even_receiver(12); always @(posedge dqs_even[13]) dqs_even_receiver(13); always @(posedge dqs_even[14]) dqs_even_receiver(14); always @(posedge dqs_even[15]) dqs_even_receiver(15); task dqs_odd_receiver; input [3:0] i; reg [63:0] bit_mask; begin bit_mask = {`DQ_PER_DQS{1'b1}}<<(i*`DQ_PER_DQS); if (dqs_odd[i]) begin if (tdqs_en) begin // tdqs disables dm dm_in_neg[i] = 1'b0; end else begin dm_in_neg[i] = dm_in[i]; end dq_in_neg = (dq_in & bit_mask) | (dq_in_neg & ~bit_mask); end end endtask always @(posedge dqs_odd[ 0]) dqs_odd_receiver( 0); always @(posedge dqs_odd[ 1]) dqs_odd_receiver( 1); always @(posedge dqs_odd[ 2]) dqs_odd_receiver( 2); always @(posedge dqs_odd[ 3]) dqs_odd_receiver( 3); always @(posedge dqs_odd[ 4]) dqs_odd_receiver( 4); always @(posedge dqs_odd[ 5]) dqs_odd_receiver( 5); always @(posedge dqs_odd[ 6]) dqs_odd_receiver( 6); always @(posedge dqs_odd[ 7]) dqs_odd_receiver( 7); always @(posedge dqs_odd[ 8]) dqs_odd_receiver( 8); always @(posedge dqs_odd[ 9]) dqs_odd_receiver( 9); always @(posedge dqs_odd[10]) dqs_odd_receiver(10); always @(posedge dqs_odd[11]) dqs_odd_receiver(11); always @(posedge dqs_odd[12]) dqs_odd_receiver(12); always @(posedge dqs_odd[13]) dqs_odd_receiver(13); always @(posedge dqs_odd[14]) dqs_odd_receiver(14); always @(posedge dqs_odd[15]) dqs_odd_receiver(15); // Processes to check hold and pulse width of control signals always @(posedge rst_n_in) begin if ($time > 100000) begin if (tm_rst_n + 100000 > $time) $display ("%m: at time %t ERROR: RST_N pulse width violation by %t", $time, tm_rst_n + 100000 - $time); end tm_rst_n = $time; end always @(cke_in) begin if (rst_n_in) begin if ($time > TIH) begin if ($time - tm_ck_pos < TIH) $display ("%m: at time %t ERROR: tIH violation on CKE by %t", $time, tm_ck_pos + TIH - $time); end if ($time - tm_cke < TIPW) $display ("%m: at time %t ERROR: tIPW violation on CKE by %t", $time, tm_cke + TIPW - $time); end tm_cke = $time; end always @(odt_in) begin if (rst_n_in && odt_en && !in_self_refresh) begin if ($time - tm_ck_pos < TIH) $display ("%m: at time %t ERROR: tIH violation on ODT by %t", $time, tm_ck_pos + TIH - $time); if ($time - tm_odt < TIPW) $display ("%m: at time %t ERROR: tIPW violation on ODT by %t", $time, tm_odt + TIPW - $time); end tm_odt = $time; end task cmd_addr_timing_check; input i; reg [4:0] i; begin if (rst_n_in && prev_cke) begin if ((i == 0) && ($time - tm_ck_pos < TIH)) // always check tIH for CS# $display ("%m: at time %t ERROR: tIH violation on %s by %t", $time, cmd_addr_string[i], tm_ck_pos + TIH - $time); if ((i > 0) && (cs_n_in == 0) &&($time - tm_ck_pos < TIH)) // Only check tIH for cmd_addr if CS# is low $display ("%m: at time %t ERROR: tIH violation on %s by %t", $time, cmd_addr_string[i], tm_ck_pos + TIH - $time); if ($time - tm_cmd_addr[i] < TIPW) $display ("%m: at time %t ERROR: tIPW violation on %s by %t", $time, cmd_addr_string[i], tm_cmd_addr[i] + TIPW - $time); end tm_cmd_addr[i] = $time; end endtask always @(cs_n_in ) cmd_addr_timing_check( 0); always @(ras_n_in ) cmd_addr_timing_check( 1); always @(cas_n_in ) cmd_addr_timing_check( 2); always @(we_n_in ) cmd_addr_timing_check( 3); always @(ba_in [ 0]) cmd_addr_timing_check( 4); always @(ba_in [ 1]) cmd_addr_timing_check( 5); always @(ba_in [ 2]) cmd_addr_timing_check( 6); always @(addr_in[ 0]) cmd_addr_timing_check( 7); always @(addr_in[ 1]) cmd_addr_timing_check( 8); always @(addr_in[ 2]) cmd_addr_timing_check( 9); always @(addr_in[ 3]) cmd_addr_timing_check(10); always @(addr_in[ 4]) cmd_addr_timing_check(11); always @(addr_in[ 5]) cmd_addr_timing_check(12); always @(addr_in[ 6]) cmd_addr_timing_check(13); always @(addr_in[ 7]) cmd_addr_timing_check(14); always @(addr_in[ 8]) cmd_addr_timing_check(15); always @(addr_in[ 9]) cmd_addr_timing_check(16); always @(addr_in[10]) cmd_addr_timing_check(17); always @(addr_in[11]) cmd_addr_timing_check(18); always @(addr_in[12]) cmd_addr_timing_check(19); always @(addr_in[13]) cmd_addr_timing_check(20); always @(addr_in[14]) cmd_addr_timing_check(21); always @(addr_in[15]) cmd_addr_timing_check(22); // Processes to check setup and hold of data signals task dm_timing_check; input i; reg [3:0] i; begin if (dqs_in_valid) begin if ($time - tm_dqs[i] < TDH) $display ("%m: at time %t ERROR: tDH violation on DM bit %d by %t", $time, i, tm_dqs[i] + TDH - $time); if (check_dm_tdipw[i]) begin if ($time - tm_dm[i] < TDIPW) $display ("%m: at time %t ERROR: tDIPW violation on DM bit %d by %t", $time, i, tm_dm[i] + TDIPW - $time); end end check_dm_tdipw[i] <= 1'b0; tm_dm[i] = $time; end endtask always @(dm_in[ 0]) dm_timing_check( 0); always @(dm_in[ 1]) dm_timing_check( 1); always @(dm_in[ 2]) dm_timing_check( 2); always @(dm_in[ 3]) dm_timing_check( 3); always @(dm_in[ 4]) dm_timing_check( 4); always @(dm_in[ 5]) dm_timing_check( 5); always @(dm_in[ 6]) dm_timing_check( 6); always @(dm_in[ 7]) dm_timing_check( 7); always @(dm_in[ 8]) dm_timing_check( 8); always @(dm_in[ 9]) dm_timing_check( 9); always @(dm_in[10]) dm_timing_check(10); always @(dm_in[11]) dm_timing_check(11); always @(dm_in[12]) dm_timing_check(12); always @(dm_in[13]) dm_timing_check(13); always @(dm_in[14]) dm_timing_check(14); always @(dm_in[15]) dm_timing_check(15); task dq_timing_check; input i; reg [5:0] i; begin if (dqs_in_valid) begin if ($time - tm_dqs[i/`DQ_PER_DQS] < TDH) $display ("%m: at time %t ERROR: tDH violation on DQ bit %d by %t", $time, i, tm_dqs[i/`DQ_PER_DQS] + TDH - $time); if (check_dq_tdipw[i]) begin if ($time - tm_dq[i] < TDIPW) $display ("%m: at time %t ERROR: tDIPW violation on DQ bit %d by %t", $time, i, tm_dq[i] + TDIPW - $time); end end check_dq_tdipw[i] <= 1'b0; tm_dq[i] = $time; end endtask always @(dq_in[ 0]) dq_timing_check( 0); always @(dq_in[ 1]) dq_timing_check( 1); always @(dq_in[ 2]) dq_timing_check( 2); always @(dq_in[ 3]) dq_timing_check( 3); always @(dq_in[ 4]) dq_timing_check( 4); always @(dq_in[ 5]) dq_timing_check( 5); always @(dq_in[ 6]) dq_timing_check( 6); always @(dq_in[ 7]) dq_timing_check( 7); always @(dq_in[ 8]) dq_timing_check( 8); always @(dq_in[ 9]) dq_timing_check( 9); always @(dq_in[10]) dq_timing_check(10); always @(dq_in[11]) dq_timing_check(11); always @(dq_in[12]) dq_timing_check(12); always @(dq_in[13]) dq_timing_check(13); always @(dq_in[14]) dq_timing_check(14); always @(dq_in[15]) dq_timing_check(15); always @(dq_in[16]) dq_timing_check(16); always @(dq_in[17]) dq_timing_check(17); always @(dq_in[18]) dq_timing_check(18); always @(dq_in[19]) dq_timing_check(19); always @(dq_in[20]) dq_timing_check(20); always @(dq_in[21]) dq_timing_check(21); always @(dq_in[22]) dq_timing_check(22); always @(dq_in[23]) dq_timing_check(23); always @(dq_in[24]) dq_timing_check(24); always @(dq_in[25]) dq_timing_check(25); always @(dq_in[26]) dq_timing_check(26); always @(dq_in[27]) dq_timing_check(27); always @(dq_in[28]) dq_timing_check(28); always @(dq_in[29]) dq_timing_check(29); always @(dq_in[30]) dq_timing_check(30); always @(dq_in[31]) dq_timing_check(31); always @(dq_in[32]) dq_timing_check(32); always @(dq_in[33]) dq_timing_check(33); always @(dq_in[34]) dq_timing_check(34); always @(dq_in[35]) dq_timing_check(35); always @(dq_in[36]) dq_timing_check(36); always @(dq_in[37]) dq_timing_check(37); always @(dq_in[38]) dq_timing_check(38); always @(dq_in[39]) dq_timing_check(39); always @(dq_in[40]) dq_timing_check(40); always @(dq_in[41]) dq_timing_check(41); always @(dq_in[42]) dq_timing_check(42); always @(dq_in[43]) dq_timing_check(43); always @(dq_in[44]) dq_timing_check(44); always @(dq_in[45]) dq_timing_check(45); always @(dq_in[46]) dq_timing_check(46); always @(dq_in[47]) dq_timing_check(47); always @(dq_in[48]) dq_timing_check(48); always @(dq_in[49]) dq_timing_check(49); always @(dq_in[50]) dq_timing_check(50); always @(dq_in[51]) dq_timing_check(51); always @(dq_in[52]) dq_timing_check(52); always @(dq_in[53]) dq_timing_check(53); always @(dq_in[54]) dq_timing_check(54); always @(dq_in[55]) dq_timing_check(55); always @(dq_in[56]) dq_timing_check(56); always @(dq_in[57]) dq_timing_check(57); always @(dq_in[58]) dq_timing_check(58); always @(dq_in[59]) dq_timing_check(59); always @(dq_in[60]) dq_timing_check(60); always @(dq_in[61]) dq_timing_check(61); always @(dq_in[62]) dq_timing_check(62); always @(dq_in[63]) dq_timing_check(63); task dqs_pos_timing_check; input i; reg [4:0] i; reg [3:0] j; begin if (write_levelization && i<16) begin if (ck_cntr - ck_load_mode < TWLMRD) $display ("%m: at time %t ERROR: tWLMRD violation on DQS bit %d positive edge.", $time, i); if (($time - tm_ck_pos < TWLS) || ($time - tm_ck_neg < TWLS)) $display ("%m: at time %t WARNING: tWLS violation on DQS bit %d positive edge. Indeterminate CK capture is possible.", $time, i); if (DEBUG) $display ("%m: at time %t Write Leveling @ DQS ck = %b", $time, diff_ck); dq_out_en_dly[i*`DQ_PER_DQS] <= #(TWLO) 1'b1; dq_out_dly[i*`DQ_PER_DQS] <= #(TWLO) diff_ck; for (j=1; j<`DQ_PER_DQS; j=j+1) begin dq_out_en_dly[i*`DQ_PER_DQS+j] <= #(TWLO + TWLOE) 1'b1; dq_out_dly[i*`DQ_PER_DQS+j] <= #(TWLO + TWLOE) 1'b0; end end if (dqs_in_valid && ((wdqs_pos_cntr[i] < wr_burst_length/2) || b2b_write)) begin if (dqs_in[i] ^ prev_dqs_in[i]) begin if (dll_locked) begin if (check_write_preamble[i]) begin if ($time - tm_dqs_pos[i] < $rtoi(TWPRE*tck_avg)) $display ("%m: at time %t ERROR: tWPRE violation on &s bit %d", $time, dqs_string[i/16], i%16); end else if (check_write_postamble[i]) begin if ($time - tm_dqs_neg[i] < $rtoi(TWPST*tck_avg)) $display ("%m: at time %t ERROR: tWPST violation on %s bit %d", $time, dqs_string[i/16], i%16); end else begin if ($time - tm_dqs_neg[i] < $rtoi(TDQSL*tck_avg)) $display ("%m: at time %t ERROR: tDQSL violation on %s bit %d", $time, dqs_string[i/16], i%16); end end if ($time - tm_dm[i%16] < TDS) $display ("%m: at time %t ERROR: tDS violation on DM bit %d by %t", $time, i, tm_dm[i%16] + TDS - $time); if (!dq_out_en) begin for (j=0; j<`DQ_PER_DQS; j=j+1) begin if ($time - tm_dq[(i%16)*`DQ_PER_DQS+j] < TDS) $display ("%m: at time %t ERROR: tDS violation on DQ bit %d by %t", $time, i*`DQ_PER_DQS+j, tm_dq[(i%16)*`DQ_PER_DQS+j] + TDS - $time); check_dq_tdipw[(i%16)*`DQ_PER_DQS+j] <= 1'b1; end end if ((wdqs_pos_cntr[i] < wr_burst_length/2) && !b2b_write) begin wdqs_pos_cntr[i] <= wdqs_pos_cntr[i] + 1; end else begin wdqs_pos_cntr[i] <= 1; end check_dm_tdipw[i%16] <= 1'b1; check_write_preamble[i] <= 1'b0; check_write_postamble[i] <= 1'b0; check_write_dqs_low[i] <= 1'b0; tm_dqs[i%16] <= $time; end else begin $display ("%m: at time %t ERROR: Invalid latching edge on %s bit %d", $time, dqs_string[i/16], i%16); end end tm_dqss_pos[i] <= $time; tm_dqs_pos[i] = $time; prev_dqs_in[i] <= dqs_in[i]; end endtask always @(posedge dqs_in[ 0]) dqs_pos_timing_check( 0); always @(posedge dqs_in[ 1]) dqs_pos_timing_check( 1); always @(posedge dqs_in[ 2]) dqs_pos_timing_check( 2); always @(posedge dqs_in[ 3]) dqs_pos_timing_check( 3); always @(posedge dqs_in[ 4]) dqs_pos_timing_check( 4); always @(posedge dqs_in[ 5]) dqs_pos_timing_check( 5); always @(posedge dqs_in[ 6]) dqs_pos_timing_check( 6); always @(posedge dqs_in[ 7]) dqs_pos_timing_check( 7); always @(posedge dqs_in[ 8]) dqs_pos_timing_check( 8); always @(posedge dqs_in[ 9]) dqs_pos_timing_check( 9); always @(posedge dqs_in[10]) dqs_pos_timing_check(10); always @(posedge dqs_in[11]) dqs_pos_timing_check(11); always @(posedge dqs_in[12]) dqs_pos_timing_check(12); always @(posedge dqs_in[13]) dqs_pos_timing_check(13); always @(posedge dqs_in[14]) dqs_pos_timing_check(14); always @(posedge dqs_in[15]) dqs_pos_timing_check(15); always @(negedge dqs_in[16]) dqs_pos_timing_check(16); always @(negedge dqs_in[17]) dqs_pos_timing_check(17); always @(negedge dqs_in[18]) dqs_pos_timing_check(18); always @(negedge dqs_in[19]) dqs_pos_timing_check(19); always @(negedge dqs_in[20]) dqs_pos_timing_check(20); always @(negedge dqs_in[21]) dqs_pos_timing_check(21); always @(negedge dqs_in[22]) dqs_pos_timing_check(22); always @(negedge dqs_in[23]) dqs_pos_timing_check(23); always @(negedge dqs_in[24]) dqs_pos_timing_check(24); always @(negedge dqs_in[25]) dqs_pos_timing_check(25); always @(negedge dqs_in[26]) dqs_pos_timing_check(26); always @(negedge dqs_in[27]) dqs_pos_timing_check(27); always @(negedge dqs_in[28]) dqs_pos_timing_check(28); always @(negedge dqs_in[29]) dqs_pos_timing_check(29); always @(negedge dqs_in[30]) dqs_pos_timing_check(30); always @(negedge dqs_in[31]) dqs_pos_timing_check(31); task dqs_neg_timing_check; input i; reg [4:0] i; reg [3:0] j; begin if (write_levelization && i<16) begin if (ck_cntr - ck_load_mode < TWLDQSEN) $display ("%m: at time %t ERROR: tWLDQSEN violation on DQS bit %d.", $time, i); if ($time - tm_dqs_pos[i] < $rtoi(TDQSH*tck_avg)) $display ("%m: at time %t ERROR: tDQSH violation on DQS bit %d by %t", $time, i, tm_dqs_pos[i] + TDQSH*tck_avg - $time); end if (dqs_in_valid && (wdqs_pos_cntr[i] > 0) && check_write_dqs_high[i]) begin if (dqs_in[i] ^ prev_dqs_in[i]) begin if (dll_locked) begin if ($time - tm_dqs_pos[i] < $rtoi(TDQSH*tck_avg)) $display ("%m: at time %t ERROR: tDQSH violation on %s bit %d", $time, dqs_string[i/16], i%16); if ($time - tm_ck_pos < $rtoi(TDSH*tck_avg)) $display ("%m: at time %t ERROR: tDSH violation on %s bit %d", $time, dqs_string[i/16], i%16); end if ($time - tm_dm[i%16] < TDS) $display ("%m: at time %t ERROR: tDS violation on DM bit %d by %t", $time, i, tm_dm[i%16] + TDS - $time); if (!dq_out_en) begin for (j=0; j<`DQ_PER_DQS; j=j+1) begin if ($time - tm_dq[(i%16)*`DQ_PER_DQS+j] < TDS) $display ("%m: at time %t ERROR: tDS violation on DQ bit %d by %t", $time, i*`DQ_PER_DQS+j, tm_dq[(i%16)*`DQ_PER_DQS+j] + TDS - $time); check_dq_tdipw[(i%16)*`DQ_PER_DQS+j] <= 1'b1; end end check_dm_tdipw[i%16] <= 1'b1; tm_dqs[i%16] <= $time; end else begin $display ("%m: at time %t ERROR: Invalid latching edge on %s bit %d", $time, dqs_string[i/16], i%16); end end check_write_dqs_high[i] <= 1'b0; tm_dqs_neg[i] = $time; prev_dqs_in[i] <= dqs_in[i]; end endtask always @(negedge dqs_in[ 0]) dqs_neg_timing_check( 0); always @(negedge dqs_in[ 1]) dqs_neg_timing_check( 1); always @(negedge dqs_in[ 2]) dqs_neg_timing_check( 2); always @(negedge dqs_in[ 3]) dqs_neg_timing_check( 3); always @(negedge dqs_in[ 4]) dqs_neg_timing_check( 4); always @(negedge dqs_in[ 5]) dqs_neg_timing_check( 5); always @(negedge dqs_in[ 6]) dqs_neg_timing_check( 6); always @(negedge dqs_in[ 7]) dqs_neg_timing_check( 7); always @(negedge dqs_in[ 8]) dqs_neg_timing_check( 8); always @(negedge dqs_in[ 9]) dqs_neg_timing_check( 9); always @(negedge dqs_in[10]) dqs_neg_timing_check(10); always @(negedge dqs_in[11]) dqs_neg_timing_check(11); always @(negedge dqs_in[12]) dqs_neg_timing_check(12); always @(negedge dqs_in[13]) dqs_neg_timing_check(13); always @(negedge dqs_in[14]) dqs_neg_timing_check(14); always @(negedge dqs_in[15]) dqs_neg_timing_check(15); always @(posedge dqs_in[16]) dqs_neg_timing_check(16); always @(posedge dqs_in[17]) dqs_neg_timing_check(17); always @(posedge dqs_in[18]) dqs_neg_timing_check(18); always @(posedge dqs_in[19]) dqs_neg_timing_check(19); always @(posedge dqs_in[20]) dqs_neg_timing_check(20); always @(posedge dqs_in[21]) dqs_neg_timing_check(21); always @(posedge dqs_in[22]) dqs_neg_timing_check(22); always @(posedge dqs_in[23]) dqs_neg_timing_check(23); always @(posedge dqs_in[24]) dqs_neg_timing_check(24); always @(posedge dqs_in[25]) dqs_neg_timing_check(25); always @(posedge dqs_in[26]) dqs_neg_timing_check(26); always @(posedge dqs_in[27]) dqs_neg_timing_check(27); always @(posedge dqs_in[28]) dqs_neg_timing_check(28); always @(posedge dqs_in[29]) dqs_neg_timing_check(29); always @(posedge dqs_in[30]) dqs_neg_timing_check(30); always @(posedge dqs_in[31]) dqs_neg_timing_check(31); endmodule
////////////////////////////////////////////////////////////////////////////////// // d_SC_KES_buffer.v for Cosmos OpenSSD // Copyright (c) 2015 Hanyang University ENC Lab. // Contributed by Jinwoo Jeong <[email protected]> // Ilyong Jung <[email protected]> // Yong Ho Song <[email protected]> // // This file is part of Cosmos OpenSSD. // // Cosmos OpenSSD 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. // // Cosmos OpenSSD 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 Cosmos OpenSSD; see the file COPYING. // If not, see <http://www.gnu.org/licenses/>. ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// // Company: ENC Lab. <http://enc.hanyang.ac.kr> // Engineer: Jinwoo Jeong <[email protected]> // Ilyong Jung <[email protected]> // // Project Name: Cosmos OpenSSD // Design Name: BCH decoder (page decoder) syndrome buffer // Module Name: d_SC_KES_buffer // File Name: d_SC_KES_buffer.v // // Version: v1.0.0 // // Description: Syndrome buffer between SC and KES // ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// // Revision History: // // * v1.0.0 // - first draft ////////////////////////////////////////////////////////////////////////////////// `timescale 1ns / 1ps module d_SC_KES_buffer #( parameter Multi = 2, parameter GF = 12, parameter Syndromes = 27 ) ( i_clk , i_RESET , i_stop_dec , i_kes_available , i_exe_buf , i_ELP_search_needed , i_syndromes , o_buf_available , o_exe_kes , o_chunk_number , o_data_fowarding , o_buf_sequence_end , o_syndromes ); input i_clk ; input i_RESET ; input i_stop_dec ; input i_kes_available ; input i_exe_buf ; input [Multi - 1:0] i_ELP_search_needed ; input [Multi*GF*Syndromes - 1:0] i_syndromes ; output reg o_exe_kes ; output o_buf_available ; output reg o_chunk_number ; output reg o_data_fowarding ; output reg o_buf_sequence_end ; output reg [Syndromes*GF - 1:0] o_syndromes ; reg [5:0] r_cur_state ; reg [5:0] r_nxt_state ; reg [2:0] r_count ; reg [Multi - 1:0] r_chunk_num ; reg r_data_fowarding ; reg [Multi*GF - 1:0] r_sdr_001 ; reg [Multi*GF - 1:0] r_sdr_002 ; reg [Multi*GF - 1:0] r_sdr_003 ; reg [Multi*GF - 1:0] r_sdr_004 ; reg [Multi*GF - 1:0] r_sdr_005 ; reg [Multi*GF - 1:0] r_sdr_006 ; reg [Multi*GF - 1:0] r_sdr_007 ; reg [Multi*GF - 1:0] r_sdr_008 ; reg [Multi*GF - 1:0] r_sdr_009 ; reg [Multi*GF - 1:0] r_sdr_010 ; reg [Multi*GF - 1:0] r_sdr_011 ; reg [Multi*GF - 1:0] r_sdr_012 ; reg [Multi*GF - 1:0] r_sdr_013 ; reg [Multi*GF - 1:0] r_sdr_014 ; reg [Multi*GF - 1:0] r_sdr_015 ; reg [Multi*GF - 1:0] r_sdr_016 ; reg [Multi*GF - 1:0] r_sdr_017 ; reg [Multi*GF - 1:0] r_sdr_018 ; reg [Multi*GF - 1:0] r_sdr_019 ; reg [Multi*GF - 1:0] r_sdr_020 ; reg [Multi*GF - 1:0] r_sdr_021 ; reg [Multi*GF - 1:0] r_sdr_022 ; reg [Multi*GF - 1:0] r_sdr_023 ; reg [Multi*GF - 1:0] r_sdr_024 ; reg [Multi*GF - 1:0] r_sdr_025 ; reg [Multi*GF - 1:0] r_sdr_026 ; reg [Multi*GF - 1:0] r_sdr_027 ; wire w_out_available ; localparam State_Idle = 6'b000001 ; localparam State_Input = 6'b000010 ; localparam State_Shift = 6'b000100 ; localparam State_Standby = 6'b001000 ; localparam State_FowardStandby = 6'b010000 ; localparam State_Output = 6'b100000 ; //assign o_exe_kes = (r_cur_state == State_Output); assign o_buf_available = (r_cur_state == State_Idle); always @ (posedge i_clk) if (i_RESET || i_stop_dec) r_cur_state <= State_Idle; else r_cur_state <= r_nxt_state; always @ (*) if (i_RESET || i_stop_dec) r_nxt_state <= State_Idle; else begin case (r_cur_state) State_Idle: r_nxt_state <= (i_exe_buf) ? State_Input : State_Idle; State_Input: r_nxt_state <= (r_chunk_num == 0)?State_FowardStandby:State_Standby; State_Standby: r_nxt_state <= (r_count == Multi) ? State_Idle : ((r_chunk_num[0] == 0) ? State_Shift : ((i_kes_available) ? State_Output : State_Standby)); State_FowardStandby: r_nxt_state <= (i_kes_available) ? State_Output : State_FowardStandby; State_Output: r_nxt_state <= ((r_count == Multi - 1) || (o_buf_sequence_end)) ? State_Idle : State_Shift; State_Shift: r_nxt_state <= State_Standby; default: r_nxt_state <= State_Idle; endcase end always @ (posedge i_clk) begin if (i_RESET || i_stop_dec) begin o_buf_sequence_end <= 0; o_exe_kes <= 0; end else begin case(r_nxt_state) State_Output: begin o_buf_sequence_end <= (r_count == Multi - 1) ? 1'b1 : (!(r_chunk_num[1]) ? 1'b1 : 1'b0); o_exe_kes <= 1'b1; end default: begin o_buf_sequence_end <= 0; o_exe_kes <= 0; end endcase end end always @ (posedge i_clk) begin if (i_RESET || i_stop_dec) r_data_fowarding <= 0; else begin case (r_nxt_state) State_Idle: r_data_fowarding <= 0; State_FowardStandby: r_data_fowarding <= 1; default: r_data_fowarding <= r_data_fowarding; endcase end end always @ (posedge i_clk) begin if (i_RESET || i_stop_dec) begin o_chunk_number <= 0; o_data_fowarding <= 0; o_syndromes <= 0; end else begin case(r_nxt_state) State_Output: begin o_chunk_number <= r_count[0]; o_data_fowarding <= r_data_fowarding; o_syndromes[Syndromes*GF - 1:0] <= { r_sdr_001[GF - 1:0], r_sdr_002[GF - 1:0], r_sdr_003[GF - 1:0], r_sdr_004[GF - 1:0], r_sdr_005[GF - 1:0], r_sdr_006[GF - 1:0], r_sdr_007[GF - 1:0], r_sdr_008[GF - 1:0], r_sdr_009[GF - 1:0], r_sdr_010[GF - 1:0], r_sdr_011[GF - 1:0], r_sdr_012[GF - 1:0], r_sdr_013[GF - 1:0], r_sdr_014[GF - 1:0], r_sdr_015[GF - 1:0], r_sdr_016[GF - 1:0], r_sdr_017[GF - 1:0], r_sdr_018[GF - 1:0], r_sdr_019[GF - 1:0], r_sdr_020[GF - 1:0], r_sdr_021[GF - 1:0], r_sdr_022[GF - 1:0], r_sdr_023[GF - 1:0], r_sdr_024[GF - 1:0], r_sdr_025[GF - 1:0], r_sdr_026[GF - 1:0], r_sdr_027[GF - 1:0] }; end default: begin o_chunk_number <= 0; o_data_fowarding <= 0; o_syndromes <= 0; end endcase end end always @ (posedge i_clk) begin if (i_RESET || i_stop_dec) begin r_count <= 0; r_chunk_num <= 0; r_sdr_001 <= 0; r_sdr_002 <= 0; r_sdr_003 <= 0; r_sdr_004 <= 0; r_sdr_005 <= 0; r_sdr_006 <= 0; r_sdr_007 <= 0; r_sdr_008 <= 0; r_sdr_009 <= 0; r_sdr_010 <= 0; r_sdr_011 <= 0; r_sdr_012 <= 0; r_sdr_013 <= 0; r_sdr_014 <= 0; r_sdr_015 <= 0; r_sdr_016 <= 0; r_sdr_017 <= 0; r_sdr_018 <= 0; r_sdr_019 <= 0; r_sdr_020 <= 0; r_sdr_021 <= 0; r_sdr_022 <= 0; r_sdr_023 <= 0; r_sdr_024 <= 0; r_sdr_025 <= 0; r_sdr_026 <= 0; r_sdr_027 <= 0; end else begin case (r_nxt_state) State_Idle: begin r_count <= 0; r_chunk_num <= 0; r_sdr_001 <= 0; r_sdr_002 <= 0; r_sdr_003 <= 0; r_sdr_004 <= 0; r_sdr_005 <= 0; r_sdr_006 <= 0; r_sdr_007 <= 0; r_sdr_008 <= 0; r_sdr_009 <= 0; r_sdr_010 <= 0; r_sdr_011 <= 0; r_sdr_012 <= 0; r_sdr_013 <= 0; r_sdr_014 <= 0; r_sdr_015 <= 0; r_sdr_016 <= 0; r_sdr_017 <= 0; r_sdr_018 <= 0; r_sdr_019 <= 0; r_sdr_020 <= 0; r_sdr_021 <= 0; r_sdr_022 <= 0; r_sdr_023 <= 0; r_sdr_024 <= 0; r_sdr_025 <= 0; r_sdr_026 <= 0; r_sdr_027 <= 0; end State_Input: begin r_count <= 0 ; r_chunk_num <= i_ELP_search_needed ; r_sdr_001 <= i_syndromes[Multi * GF * (Syndromes+1 - 1) - 1 : Multi * GF * (Syndromes+1 - 2)]; r_sdr_002 <= i_syndromes[Multi * GF * (Syndromes+1 - 2) - 1 : Multi * GF * (Syndromes+1 - 3)]; r_sdr_003 <= i_syndromes[Multi * GF * (Syndromes+1 - 3) - 1 : Multi * GF * (Syndromes+1 - 4)]; r_sdr_004 <= i_syndromes[Multi * GF * (Syndromes+1 - 4) - 1 : Multi * GF * (Syndromes+1 - 5)]; r_sdr_005 <= i_syndromes[Multi * GF * (Syndromes+1 - 5) - 1 : Multi * GF * (Syndromes+1 - 6)]; r_sdr_006 <= i_syndromes[Multi * GF * (Syndromes+1 - 6) - 1 : Multi * GF * (Syndromes+1 - 7)]; r_sdr_007 <= i_syndromes[Multi * GF * (Syndromes+1 - 7) - 1 : Multi * GF * (Syndromes+1 - 8)]; r_sdr_008 <= i_syndromes[Multi * GF * (Syndromes+1 - 8) - 1 : Multi * GF * (Syndromes+1 - 9)]; r_sdr_009 <= i_syndromes[Multi * GF * (Syndromes+1 - 9) - 1 : Multi * GF * (Syndromes+1 - 10)]; r_sdr_010 <= i_syndromes[Multi * GF * (Syndromes+1 - 10) - 1 : Multi * GF * (Syndromes+1 - 11)]; r_sdr_011 <= i_syndromes[Multi * GF * (Syndromes+1 - 11) - 1 : Multi * GF * (Syndromes+1 - 12)]; r_sdr_012 <= i_syndromes[Multi * GF * (Syndromes+1 - 12) - 1 : Multi * GF * (Syndromes+1 - 13)]; r_sdr_013 <= i_syndromes[Multi * GF * (Syndromes+1 - 13) - 1 : Multi * GF * (Syndromes+1 - 14)]; r_sdr_014 <= i_syndromes[Multi * GF * (Syndromes+1 - 14) - 1 : Multi * GF * (Syndromes+1 - 15)]; r_sdr_015 <= i_syndromes[Multi * GF * (Syndromes+1 - 15) - 1 : Multi * GF * (Syndromes+1 - 16)]; r_sdr_016 <= i_syndromes[Multi * GF * (Syndromes+1 - 16) - 1 : Multi * GF * (Syndromes+1 - 17)]; r_sdr_017 <= i_syndromes[Multi * GF * (Syndromes+1 - 17) - 1 : Multi * GF * (Syndromes+1 - 18)]; r_sdr_018 <= i_syndromes[Multi * GF * (Syndromes+1 - 18) - 1 : Multi * GF * (Syndromes+1 - 19)]; r_sdr_019 <= i_syndromes[Multi * GF * (Syndromes+1 - 19) - 1 : Multi * GF * (Syndromes+1 - 20)]; r_sdr_020 <= i_syndromes[Multi * GF * (Syndromes+1 - 20) - 1 : Multi * GF * (Syndromes+1 - 21)]; r_sdr_021 <= i_syndromes[Multi * GF * (Syndromes+1 - 21) - 1 : Multi * GF * (Syndromes+1 - 22)]; r_sdr_022 <= i_syndromes[Multi * GF * (Syndromes+1 - 22) - 1 : Multi * GF * (Syndromes+1 - 23)]; r_sdr_023 <= i_syndromes[Multi * GF * (Syndromes+1 - 23) - 1 : Multi * GF * (Syndromes+1 - 24)]; r_sdr_024 <= i_syndromes[Multi * GF * (Syndromes+1 - 24) - 1 : Multi * GF * (Syndromes+1 - 25)]; r_sdr_025 <= i_syndromes[Multi * GF * (Syndromes+1 - 25) - 1 : Multi * GF * (Syndromes+1 - 26)]; r_sdr_026 <= i_syndromes[Multi * GF * (Syndromes+1 - 26) - 1 : Multi * GF * (Syndromes+1 - 27)]; r_sdr_027 <= i_syndromes[Multi * GF * (Syndromes+1 - 27) - 1 : Multi * GF * (Syndromes+1 - 28)]; end State_Shift: begin r_count <= r_count + 1'b1; r_chunk_num <= r_chunk_num >> 1; r_sdr_001 <= r_sdr_001 >> GF; r_sdr_002 <= r_sdr_002 >> GF; r_sdr_003 <= r_sdr_003 >> GF; r_sdr_004 <= r_sdr_004 >> GF; r_sdr_005 <= r_sdr_005 >> GF; r_sdr_006 <= r_sdr_006 >> GF; r_sdr_007 <= r_sdr_007 >> GF; r_sdr_008 <= r_sdr_008 >> GF; r_sdr_009 <= r_sdr_009 >> GF; r_sdr_010 <= r_sdr_010 >> GF; r_sdr_011 <= r_sdr_011 >> GF; r_sdr_012 <= r_sdr_012 >> GF; r_sdr_013 <= r_sdr_013 >> GF; r_sdr_014 <= r_sdr_014 >> GF; r_sdr_015 <= r_sdr_015 >> GF; r_sdr_016 <= r_sdr_016 >> GF; r_sdr_017 <= r_sdr_017 >> GF; r_sdr_018 <= r_sdr_018 >> GF; r_sdr_019 <= r_sdr_019 >> GF; r_sdr_020 <= r_sdr_020 >> GF; r_sdr_021 <= r_sdr_021 >> GF; r_sdr_022 <= r_sdr_022 >> GF; r_sdr_023 <= r_sdr_023 >> GF; r_sdr_024 <= r_sdr_024 >> GF; r_sdr_025 <= r_sdr_025 >> GF; r_sdr_026 <= r_sdr_026 >> GF; r_sdr_027 <= r_sdr_027 >> GF; end default: begin r_count <= r_count; r_chunk_num <= r_chunk_num; r_sdr_001 <= r_sdr_001; r_sdr_002 <= r_sdr_002; r_sdr_003 <= r_sdr_003; r_sdr_004 <= r_sdr_004; r_sdr_005 <= r_sdr_005; r_sdr_006 <= r_sdr_006; r_sdr_007 <= r_sdr_007; r_sdr_008 <= r_sdr_008; r_sdr_009 <= r_sdr_009; r_sdr_010 <= r_sdr_010; r_sdr_011 <= r_sdr_011; r_sdr_012 <= r_sdr_012; r_sdr_013 <= r_sdr_013; r_sdr_014 <= r_sdr_014; r_sdr_015 <= r_sdr_015; r_sdr_016 <= r_sdr_016; r_sdr_017 <= r_sdr_017; r_sdr_018 <= r_sdr_018; r_sdr_019 <= r_sdr_019; r_sdr_020 <= r_sdr_020; r_sdr_021 <= r_sdr_021; r_sdr_022 <= r_sdr_022; r_sdr_023 <= r_sdr_023; r_sdr_024 <= r_sdr_024; r_sdr_025 <= r_sdr_025; r_sdr_026 <= r_sdr_026; r_sdr_027 <= r_sdr_027; end endcase end end endmodule
////////////////////////////////////////////////////////////////////////////////// // d_SC_KES_buffer.v for Cosmos OpenSSD // Copyright (c) 2015 Hanyang University ENC Lab. // Contributed by Jinwoo Jeong <[email protected]> // Ilyong Jung <[email protected]> // Yong Ho Song <[email protected]> // // This file is part of Cosmos OpenSSD. // // Cosmos OpenSSD 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. // // Cosmos OpenSSD 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 Cosmos OpenSSD; see the file COPYING. // If not, see <http://www.gnu.org/licenses/>. ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// // Company: ENC Lab. <http://enc.hanyang.ac.kr> // Engineer: Jinwoo Jeong <[email protected]> // Ilyong Jung <[email protected]> // // Project Name: Cosmos OpenSSD // Design Name: BCH decoder (page decoder) syndrome buffer // Module Name: d_SC_KES_buffer // File Name: d_SC_KES_buffer.v // // Version: v1.0.0 // // Description: Syndrome buffer between SC and KES // ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// // Revision History: // // * v1.0.0 // - first draft ////////////////////////////////////////////////////////////////////////////////// `timescale 1ns / 1ps module d_SC_KES_buffer #( parameter Multi = 2, parameter GF = 12, parameter Syndromes = 27 ) ( i_clk , i_RESET , i_stop_dec , i_kes_available , i_exe_buf , i_ELP_search_needed , i_syndromes , o_buf_available , o_exe_kes , o_chunk_number , o_data_fowarding , o_buf_sequence_end , o_syndromes ); input i_clk ; input i_RESET ; input i_stop_dec ; input i_kes_available ; input i_exe_buf ; input [Multi - 1:0] i_ELP_search_needed ; input [Multi*GF*Syndromes - 1:0] i_syndromes ; output reg o_exe_kes ; output o_buf_available ; output reg o_chunk_number ; output reg o_data_fowarding ; output reg o_buf_sequence_end ; output reg [Syndromes*GF - 1:0] o_syndromes ; reg [5:0] r_cur_state ; reg [5:0] r_nxt_state ; reg [2:0] r_count ; reg [Multi - 1:0] r_chunk_num ; reg r_data_fowarding ; reg [Multi*GF - 1:0] r_sdr_001 ; reg [Multi*GF - 1:0] r_sdr_002 ; reg [Multi*GF - 1:0] r_sdr_003 ; reg [Multi*GF - 1:0] r_sdr_004 ; reg [Multi*GF - 1:0] r_sdr_005 ; reg [Multi*GF - 1:0] r_sdr_006 ; reg [Multi*GF - 1:0] r_sdr_007 ; reg [Multi*GF - 1:0] r_sdr_008 ; reg [Multi*GF - 1:0] r_sdr_009 ; reg [Multi*GF - 1:0] r_sdr_010 ; reg [Multi*GF - 1:0] r_sdr_011 ; reg [Multi*GF - 1:0] r_sdr_012 ; reg [Multi*GF - 1:0] r_sdr_013 ; reg [Multi*GF - 1:0] r_sdr_014 ; reg [Multi*GF - 1:0] r_sdr_015 ; reg [Multi*GF - 1:0] r_sdr_016 ; reg [Multi*GF - 1:0] r_sdr_017 ; reg [Multi*GF - 1:0] r_sdr_018 ; reg [Multi*GF - 1:0] r_sdr_019 ; reg [Multi*GF - 1:0] r_sdr_020 ; reg [Multi*GF - 1:0] r_sdr_021 ; reg [Multi*GF - 1:0] r_sdr_022 ; reg [Multi*GF - 1:0] r_sdr_023 ; reg [Multi*GF - 1:0] r_sdr_024 ; reg [Multi*GF - 1:0] r_sdr_025 ; reg [Multi*GF - 1:0] r_sdr_026 ; reg [Multi*GF - 1:0] r_sdr_027 ; wire w_out_available ; localparam State_Idle = 6'b000001 ; localparam State_Input = 6'b000010 ; localparam State_Shift = 6'b000100 ; localparam State_Standby = 6'b001000 ; localparam State_FowardStandby = 6'b010000 ; localparam State_Output = 6'b100000 ; //assign o_exe_kes = (r_cur_state == State_Output); assign o_buf_available = (r_cur_state == State_Idle); always @ (posedge i_clk) if (i_RESET || i_stop_dec) r_cur_state <= State_Idle; else r_cur_state <= r_nxt_state; always @ (*) if (i_RESET || i_stop_dec) r_nxt_state <= State_Idle; else begin case (r_cur_state) State_Idle: r_nxt_state <= (i_exe_buf) ? State_Input : State_Idle; State_Input: r_nxt_state <= (r_chunk_num == 0)?State_FowardStandby:State_Standby; State_Standby: r_nxt_state <= (r_count == Multi) ? State_Idle : ((r_chunk_num[0] == 0) ? State_Shift : ((i_kes_available) ? State_Output : State_Standby)); State_FowardStandby: r_nxt_state <= (i_kes_available) ? State_Output : State_FowardStandby; State_Output: r_nxt_state <= ((r_count == Multi - 1) || (o_buf_sequence_end)) ? State_Idle : State_Shift; State_Shift: r_nxt_state <= State_Standby; default: r_nxt_state <= State_Idle; endcase end always @ (posedge i_clk) begin if (i_RESET || i_stop_dec) begin o_buf_sequence_end <= 0; o_exe_kes <= 0; end else begin case(r_nxt_state) State_Output: begin o_buf_sequence_end <= (r_count == Multi - 1) ? 1'b1 : (!(r_chunk_num[1]) ? 1'b1 : 1'b0); o_exe_kes <= 1'b1; end default: begin o_buf_sequence_end <= 0; o_exe_kes <= 0; end endcase end end always @ (posedge i_clk) begin if (i_RESET || i_stop_dec) r_data_fowarding <= 0; else begin case (r_nxt_state) State_Idle: r_data_fowarding <= 0; State_FowardStandby: r_data_fowarding <= 1; default: r_data_fowarding <= r_data_fowarding; endcase end end always @ (posedge i_clk) begin if (i_RESET || i_stop_dec) begin o_chunk_number <= 0; o_data_fowarding <= 0; o_syndromes <= 0; end else begin case(r_nxt_state) State_Output: begin o_chunk_number <= r_count[0]; o_data_fowarding <= r_data_fowarding; o_syndromes[Syndromes*GF - 1:0] <= { r_sdr_001[GF - 1:0], r_sdr_002[GF - 1:0], r_sdr_003[GF - 1:0], r_sdr_004[GF - 1:0], r_sdr_005[GF - 1:0], r_sdr_006[GF - 1:0], r_sdr_007[GF - 1:0], r_sdr_008[GF - 1:0], r_sdr_009[GF - 1:0], r_sdr_010[GF - 1:0], r_sdr_011[GF - 1:0], r_sdr_012[GF - 1:0], r_sdr_013[GF - 1:0], r_sdr_014[GF - 1:0], r_sdr_015[GF - 1:0], r_sdr_016[GF - 1:0], r_sdr_017[GF - 1:0], r_sdr_018[GF - 1:0], r_sdr_019[GF - 1:0], r_sdr_020[GF - 1:0], r_sdr_021[GF - 1:0], r_sdr_022[GF - 1:0], r_sdr_023[GF - 1:0], r_sdr_024[GF - 1:0], r_sdr_025[GF - 1:0], r_sdr_026[GF - 1:0], r_sdr_027[GF - 1:0] }; end default: begin o_chunk_number <= 0; o_data_fowarding <= 0; o_syndromes <= 0; end endcase end end always @ (posedge i_clk) begin if (i_RESET || i_stop_dec) begin r_count <= 0; r_chunk_num <= 0; r_sdr_001 <= 0; r_sdr_002 <= 0; r_sdr_003 <= 0; r_sdr_004 <= 0; r_sdr_005 <= 0; r_sdr_006 <= 0; r_sdr_007 <= 0; r_sdr_008 <= 0; r_sdr_009 <= 0; r_sdr_010 <= 0; r_sdr_011 <= 0; r_sdr_012 <= 0; r_sdr_013 <= 0; r_sdr_014 <= 0; r_sdr_015 <= 0; r_sdr_016 <= 0; r_sdr_017 <= 0; r_sdr_018 <= 0; r_sdr_019 <= 0; r_sdr_020 <= 0; r_sdr_021 <= 0; r_sdr_022 <= 0; r_sdr_023 <= 0; r_sdr_024 <= 0; r_sdr_025 <= 0; r_sdr_026 <= 0; r_sdr_027 <= 0; end else begin case (r_nxt_state) State_Idle: begin r_count <= 0; r_chunk_num <= 0; r_sdr_001 <= 0; r_sdr_002 <= 0; r_sdr_003 <= 0; r_sdr_004 <= 0; r_sdr_005 <= 0; r_sdr_006 <= 0; r_sdr_007 <= 0; r_sdr_008 <= 0; r_sdr_009 <= 0; r_sdr_010 <= 0; r_sdr_011 <= 0; r_sdr_012 <= 0; r_sdr_013 <= 0; r_sdr_014 <= 0; r_sdr_015 <= 0; r_sdr_016 <= 0; r_sdr_017 <= 0; r_sdr_018 <= 0; r_sdr_019 <= 0; r_sdr_020 <= 0; r_sdr_021 <= 0; r_sdr_022 <= 0; r_sdr_023 <= 0; r_sdr_024 <= 0; r_sdr_025 <= 0; r_sdr_026 <= 0; r_sdr_027 <= 0; end State_Input: begin r_count <= 0 ; r_chunk_num <= i_ELP_search_needed ; r_sdr_001 <= i_syndromes[Multi * GF * (Syndromes+1 - 1) - 1 : Multi * GF * (Syndromes+1 - 2)]; r_sdr_002 <= i_syndromes[Multi * GF * (Syndromes+1 - 2) - 1 : Multi * GF * (Syndromes+1 - 3)]; r_sdr_003 <= i_syndromes[Multi * GF * (Syndromes+1 - 3) - 1 : Multi * GF * (Syndromes+1 - 4)]; r_sdr_004 <= i_syndromes[Multi * GF * (Syndromes+1 - 4) - 1 : Multi * GF * (Syndromes+1 - 5)]; r_sdr_005 <= i_syndromes[Multi * GF * (Syndromes+1 - 5) - 1 : Multi * GF * (Syndromes+1 - 6)]; r_sdr_006 <= i_syndromes[Multi * GF * (Syndromes+1 - 6) - 1 : Multi * GF * (Syndromes+1 - 7)]; r_sdr_007 <= i_syndromes[Multi * GF * (Syndromes+1 - 7) - 1 : Multi * GF * (Syndromes+1 - 8)]; r_sdr_008 <= i_syndromes[Multi * GF * (Syndromes+1 - 8) - 1 : Multi * GF * (Syndromes+1 - 9)]; r_sdr_009 <= i_syndromes[Multi * GF * (Syndromes+1 - 9) - 1 : Multi * GF * (Syndromes+1 - 10)]; r_sdr_010 <= i_syndromes[Multi * GF * (Syndromes+1 - 10) - 1 : Multi * GF * (Syndromes+1 - 11)]; r_sdr_011 <= i_syndromes[Multi * GF * (Syndromes+1 - 11) - 1 : Multi * GF * (Syndromes+1 - 12)]; r_sdr_012 <= i_syndromes[Multi * GF * (Syndromes+1 - 12) - 1 : Multi * GF * (Syndromes+1 - 13)]; r_sdr_013 <= i_syndromes[Multi * GF * (Syndromes+1 - 13) - 1 : Multi * GF * (Syndromes+1 - 14)]; r_sdr_014 <= i_syndromes[Multi * GF * (Syndromes+1 - 14) - 1 : Multi * GF * (Syndromes+1 - 15)]; r_sdr_015 <= i_syndromes[Multi * GF * (Syndromes+1 - 15) - 1 : Multi * GF * (Syndromes+1 - 16)]; r_sdr_016 <= i_syndromes[Multi * GF * (Syndromes+1 - 16) - 1 : Multi * GF * (Syndromes+1 - 17)]; r_sdr_017 <= i_syndromes[Multi * GF * (Syndromes+1 - 17) - 1 : Multi * GF * (Syndromes+1 - 18)]; r_sdr_018 <= i_syndromes[Multi * GF * (Syndromes+1 - 18) - 1 : Multi * GF * (Syndromes+1 - 19)]; r_sdr_019 <= i_syndromes[Multi * GF * (Syndromes+1 - 19) - 1 : Multi * GF * (Syndromes+1 - 20)]; r_sdr_020 <= i_syndromes[Multi * GF * (Syndromes+1 - 20) - 1 : Multi * GF * (Syndromes+1 - 21)]; r_sdr_021 <= i_syndromes[Multi * GF * (Syndromes+1 - 21) - 1 : Multi * GF * (Syndromes+1 - 22)]; r_sdr_022 <= i_syndromes[Multi * GF * (Syndromes+1 - 22) - 1 : Multi * GF * (Syndromes+1 - 23)]; r_sdr_023 <= i_syndromes[Multi * GF * (Syndromes+1 - 23) - 1 : Multi * GF * (Syndromes+1 - 24)]; r_sdr_024 <= i_syndromes[Multi * GF * (Syndromes+1 - 24) - 1 : Multi * GF * (Syndromes+1 - 25)]; r_sdr_025 <= i_syndromes[Multi * GF * (Syndromes+1 - 25) - 1 : Multi * GF * (Syndromes+1 - 26)]; r_sdr_026 <= i_syndromes[Multi * GF * (Syndromes+1 - 26) - 1 : Multi * GF * (Syndromes+1 - 27)]; r_sdr_027 <= i_syndromes[Multi * GF * (Syndromes+1 - 27) - 1 : Multi * GF * (Syndromes+1 - 28)]; end State_Shift: begin r_count <= r_count + 1'b1; r_chunk_num <= r_chunk_num >> 1; r_sdr_001 <= r_sdr_001 >> GF; r_sdr_002 <= r_sdr_002 >> GF; r_sdr_003 <= r_sdr_003 >> GF; r_sdr_004 <= r_sdr_004 >> GF; r_sdr_005 <= r_sdr_005 >> GF; r_sdr_006 <= r_sdr_006 >> GF; r_sdr_007 <= r_sdr_007 >> GF; r_sdr_008 <= r_sdr_008 >> GF; r_sdr_009 <= r_sdr_009 >> GF; r_sdr_010 <= r_sdr_010 >> GF; r_sdr_011 <= r_sdr_011 >> GF; r_sdr_012 <= r_sdr_012 >> GF; r_sdr_013 <= r_sdr_013 >> GF; r_sdr_014 <= r_sdr_014 >> GF; r_sdr_015 <= r_sdr_015 >> GF; r_sdr_016 <= r_sdr_016 >> GF; r_sdr_017 <= r_sdr_017 >> GF; r_sdr_018 <= r_sdr_018 >> GF; r_sdr_019 <= r_sdr_019 >> GF; r_sdr_020 <= r_sdr_020 >> GF; r_sdr_021 <= r_sdr_021 >> GF; r_sdr_022 <= r_sdr_022 >> GF; r_sdr_023 <= r_sdr_023 >> GF; r_sdr_024 <= r_sdr_024 >> GF; r_sdr_025 <= r_sdr_025 >> GF; r_sdr_026 <= r_sdr_026 >> GF; r_sdr_027 <= r_sdr_027 >> GF; end default: begin r_count <= r_count; r_chunk_num <= r_chunk_num; r_sdr_001 <= r_sdr_001; r_sdr_002 <= r_sdr_002; r_sdr_003 <= r_sdr_003; r_sdr_004 <= r_sdr_004; r_sdr_005 <= r_sdr_005; r_sdr_006 <= r_sdr_006; r_sdr_007 <= r_sdr_007; r_sdr_008 <= r_sdr_008; r_sdr_009 <= r_sdr_009; r_sdr_010 <= r_sdr_010; r_sdr_011 <= r_sdr_011; r_sdr_012 <= r_sdr_012; r_sdr_013 <= r_sdr_013; r_sdr_014 <= r_sdr_014; r_sdr_015 <= r_sdr_015; r_sdr_016 <= r_sdr_016; r_sdr_017 <= r_sdr_017; r_sdr_018 <= r_sdr_018; r_sdr_019 <= r_sdr_019; r_sdr_020 <= r_sdr_020; r_sdr_021 <= r_sdr_021; r_sdr_022 <= r_sdr_022; r_sdr_023 <= r_sdr_023; r_sdr_024 <= r_sdr_024; r_sdr_025 <= r_sdr_025; r_sdr_026 <= r_sdr_026; r_sdr_027 <= r_sdr_027; end endcase end end endmodule
`timescale 1ns/10ps module soc_design_system_pll( // interface 'refclk' input wire refclk, // interface 'reset' input wire rst, // interface 'outclk0' output wire outclk_0, // interface 'outclk1' output wire outclk_1, // interface 'locked' output wire locked ); altera_pll #( .fractional_vco_multiplier("false"), .reference_clock_frequency("50.0 MHz"), .operation_mode("direct"), .number_of_clocks(2), .output_clock_frequency0("100.000000 MHz"), .phase_shift0("0 ps"), .duty_cycle0(50), .output_clock_frequency1("100.000000 MHz"), .phase_shift1("8250 ps"), .duty_cycle1(50), .output_clock_frequency2("0 MHz"), .phase_shift2("0 ps"), .duty_cycle2(50), .output_clock_frequency3("0 MHz"), .phase_shift3("0 ps"), .duty_cycle3(50), .output_clock_frequency4("0 MHz"), .phase_shift4("0 ps"), .duty_cycle4(50), .output_clock_frequency5("0 MHz"), .phase_shift5("0 ps"), .duty_cycle5(50), .output_clock_frequency6("0 MHz"), .phase_shift6("0 ps"), .duty_cycle6(50), .output_clock_frequency7("0 MHz"), .phase_shift7("0 ps"), .duty_cycle7(50), .output_clock_frequency8("0 MHz"), .phase_shift8("0 ps"), .duty_cycle8(50), .output_clock_frequency9("0 MHz"), .phase_shift9("0 ps"), .duty_cycle9(50), .output_clock_frequency10("0 MHz"), .phase_shift10("0 ps"), .duty_cycle10(50), .output_clock_frequency11("0 MHz"), .phase_shift11("0 ps"), .duty_cycle11(50), .output_clock_frequency12("0 MHz"), .phase_shift12("0 ps"), .duty_cycle12(50), .output_clock_frequency13("0 MHz"), .phase_shift13("0 ps"), .duty_cycle13(50), .output_clock_frequency14("0 MHz"), .phase_shift14("0 ps"), .duty_cycle14(50), .output_clock_frequency15("0 MHz"), .phase_shift15("0 ps"), .duty_cycle15(50), .output_clock_frequency16("0 MHz"), .phase_shift16("0 ps"), .duty_cycle16(50), .output_clock_frequency17("0 MHz"), .phase_shift17("0 ps"), .duty_cycle17(50), .pll_type("General"), .pll_subtype("General") ) altera_pll_i ( .rst (rst), .outclk ({outclk_1, outclk_0}), .locked (locked), .fboutclk ( ), .fbclk (1'b0), .refclk (refclk) ); endmodule
`timescale 1ns/10ps module soc_design_system_pll( // interface 'refclk' input wire refclk, // interface 'reset' input wire rst, // interface 'outclk0' output wire outclk_0, // interface 'outclk1' output wire outclk_1, // interface 'locked' output wire locked ); altera_pll #( .fractional_vco_multiplier("false"), .reference_clock_frequency("50.0 MHz"), .operation_mode("direct"), .number_of_clocks(2), .output_clock_frequency0("100.000000 MHz"), .phase_shift0("0 ps"), .duty_cycle0(50), .output_clock_frequency1("100.000000 MHz"), .phase_shift1("8250 ps"), .duty_cycle1(50), .output_clock_frequency2("0 MHz"), .phase_shift2("0 ps"), .duty_cycle2(50), .output_clock_frequency3("0 MHz"), .phase_shift3("0 ps"), .duty_cycle3(50), .output_clock_frequency4("0 MHz"), .phase_shift4("0 ps"), .duty_cycle4(50), .output_clock_frequency5("0 MHz"), .phase_shift5("0 ps"), .duty_cycle5(50), .output_clock_frequency6("0 MHz"), .phase_shift6("0 ps"), .duty_cycle6(50), .output_clock_frequency7("0 MHz"), .phase_shift7("0 ps"), .duty_cycle7(50), .output_clock_frequency8("0 MHz"), .phase_shift8("0 ps"), .duty_cycle8(50), .output_clock_frequency9("0 MHz"), .phase_shift9("0 ps"), .duty_cycle9(50), .output_clock_frequency10("0 MHz"), .phase_shift10("0 ps"), .duty_cycle10(50), .output_clock_frequency11("0 MHz"), .phase_shift11("0 ps"), .duty_cycle11(50), .output_clock_frequency12("0 MHz"), .phase_shift12("0 ps"), .duty_cycle12(50), .output_clock_frequency13("0 MHz"), .phase_shift13("0 ps"), .duty_cycle13(50), .output_clock_frequency14("0 MHz"), .phase_shift14("0 ps"), .duty_cycle14(50), .output_clock_frequency15("0 MHz"), .phase_shift15("0 ps"), .duty_cycle15(50), .output_clock_frequency16("0 MHz"), .phase_shift16("0 ps"), .duty_cycle16(50), .output_clock_frequency17("0 MHz"), .phase_shift17("0 ps"), .duty_cycle17(50), .pll_type("General"), .pll_subtype("General") ) altera_pll_i ( .rst (rst), .outclk ({outclk_1, outclk_0}), .locked (locked), .fboutclk ( ), .fbclk (1'b0), .refclk (refclk) ); endmodule
//Legal Notice: (C)2017 Altera Corporation. All rights reserved. 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 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. // synthesis translate_off `timescale 1ns / 1ps // synthesis translate_on // turn off superfluous verilog processor warnings // altera message_level Level1 // altera message_off 10034 10035 10036 10037 10230 10240 10030 module soc_design_SDRAM_input_efifo_module ( // inputs: clk, rd, reset_n, wr, wr_data, // outputs: almost_empty, almost_full, empty, full, rd_data ) ; output almost_empty; output almost_full; output empty; output full; output [ 43: 0] rd_data; input clk; input rd; input reset_n; input wr; input [ 43: 0] wr_data; wire almost_empty; wire almost_full; wire empty; reg [ 1: 0] entries; reg [ 43: 0] entry_0; reg [ 43: 0] entry_1; wire full; reg rd_address; reg [ 43: 0] rd_data; wire [ 1: 0] rdwr; reg wr_address; assign rdwr = {rd, wr}; assign full = entries == 2; assign almost_full = entries >= 1; assign empty = entries == 0; assign almost_empty = entries <= 1; always @(entry_0 or entry_1 or rd_address) begin case (rd_address) // synthesis parallel_case full_case 1'd0: begin rd_data = entry_0; end // 1'd0 1'd1: begin rd_data = entry_1; end // 1'd1 default: begin end // default endcase // rd_address end always @(posedge clk or negedge reset_n) begin if (reset_n == 0) begin wr_address <= 0; rd_address <= 0; entries <= 0; end else case (rdwr) // synthesis parallel_case full_case 2'd1: begin // Write data if (!full) begin entries <= entries + 1; wr_address <= (wr_address == 1) ? 0 : (wr_address + 1); end end // 2'd1 2'd2: begin // Read data if (!empty) begin entries <= entries - 1; rd_address <= (rd_address == 1) ? 0 : (rd_address + 1); end end // 2'd2 2'd3: begin wr_address <= (wr_address == 1) ? 0 : (wr_address + 1); rd_address <= (rd_address == 1) ? 0 : (rd_address + 1); end // 2'd3 default: begin end // default endcase // rdwr end always @(posedge clk) begin //Write data if (wr & !full) case (wr_address) // synthesis parallel_case full_case 1'd0: begin entry_0 <= wr_data; end // 1'd0 1'd1: begin entry_1 <= wr_data; end // 1'd1 default: begin end // default endcase // wr_address end endmodule // synthesis translate_off `timescale 1ns / 1ps // synthesis translate_on // turn off superfluous verilog processor warnings // altera message_level Level1 // altera message_off 10034 10035 10036 10037 10230 10240 10030 module soc_design_SDRAM ( // inputs: az_addr, az_be_n, az_cs, az_data, az_rd_n, az_wr_n, clk, reset_n, // outputs: za_data, za_valid, za_waitrequest, zs_addr, zs_ba, zs_cas_n, zs_cke, zs_cs_n, zs_dq, zs_dqm, zs_ras_n, zs_we_n ) ; output [ 15: 0] za_data; output za_valid; output za_waitrequest; output [ 12: 0] zs_addr; output [ 1: 0] zs_ba; output zs_cas_n; output zs_cke; output zs_cs_n; inout [ 15: 0] zs_dq; output [ 1: 0] zs_dqm; output zs_ras_n; output zs_we_n; input [ 24: 0] az_addr; input [ 1: 0] az_be_n; input az_cs; input [ 15: 0] az_data; input az_rd_n; input az_wr_n; input clk; input reset_n; wire [ 23: 0] CODE; reg ack_refresh_request; reg [ 24: 0] active_addr; wire [ 1: 0] active_bank; reg active_cs_n; reg [ 15: 0] active_data; reg [ 1: 0] active_dqm; reg active_rnw; wire almost_empty; wire almost_full; wire bank_match; wire [ 9: 0] cas_addr; wire clk_en; wire [ 3: 0] cmd_all; wire [ 2: 0] cmd_code; wire cs_n; wire csn_decode; wire csn_match; wire [ 24: 0] f_addr; wire [ 1: 0] f_bank; wire f_cs_n; wire [ 15: 0] f_data; wire [ 1: 0] f_dqm; wire f_empty; reg f_pop; wire f_rnw; wire f_select; wire [ 43: 0] fifo_read_data; reg [ 12: 0] i_addr; reg [ 3: 0] i_cmd; reg [ 2: 0] i_count; reg [ 2: 0] i_next; reg [ 2: 0] i_refs; reg [ 2: 0] i_state; reg init_done; reg [ 12: 0] m_addr /* synthesis ALTERA_ATTRIBUTE = "FAST_OUTPUT_REGISTER=ON" */; reg [ 1: 0] m_bank /* synthesis ALTERA_ATTRIBUTE = "FAST_OUTPUT_REGISTER=ON" */; reg [ 3: 0] m_cmd /* synthesis ALTERA_ATTRIBUTE = "FAST_OUTPUT_REGISTER=ON" */; reg [ 2: 0] m_count; reg [ 15: 0] m_data /* synthesis ALTERA_ATTRIBUTE = "FAST_OUTPUT_REGISTER=ON ; FAST_OUTPUT_ENABLE_REGISTER=ON" */; reg [ 1: 0] m_dqm /* synthesis ALTERA_ATTRIBUTE = "FAST_OUTPUT_REGISTER=ON" */; reg [ 8: 0] m_next; reg [ 8: 0] m_state; reg oe /* synthesis ALTERA_ATTRIBUTE = "FAST_OUTPUT_ENABLE_REGISTER=ON" */; wire pending; wire rd_strobe; reg [ 2: 0] rd_valid; reg [ 14: 0] refresh_counter; reg refresh_request; wire rnw_match; wire row_match; wire [ 23: 0] txt_code; reg za_cannotrefresh; reg [ 15: 0] za_data /* synthesis ALTERA_ATTRIBUTE = "FAST_INPUT_REGISTER=ON" */; reg za_valid; wire za_waitrequest; wire [ 12: 0] zs_addr; wire [ 1: 0] zs_ba; wire zs_cas_n; wire zs_cke; wire zs_cs_n; wire [ 15: 0] zs_dq; wire [ 1: 0] zs_dqm; wire zs_ras_n; wire zs_we_n; assign clk_en = 1; //s1, which is an e_avalon_slave assign {zs_cs_n, zs_ras_n, zs_cas_n, zs_we_n} = m_cmd; assign zs_addr = m_addr; assign zs_cke = clk_en; assign zs_dq = oe?m_data:{16{1'bz}}; assign zs_dqm = m_dqm; assign zs_ba = m_bank; assign f_select = f_pop & pending; assign f_cs_n = 1'b0; assign cs_n = f_select ? f_cs_n : active_cs_n; assign csn_decode = cs_n; assign {f_rnw, f_addr, f_dqm, f_data} = fifo_read_data; soc_design_SDRAM_input_efifo_module the_soc_design_SDRAM_input_efifo_module ( .almost_empty (almost_empty), .almost_full (almost_full), .clk (clk), .empty (f_empty), .full (za_waitrequest), .rd (f_select), .rd_data (fifo_read_data), .reset_n (reset_n), .wr ((~az_wr_n | ~az_rd_n) & !za_waitrequest), .wr_data ({az_wr_n, az_addr, az_wr_n ? 2'b0 : az_be_n, az_data}) ); assign f_bank = {f_addr[24],f_addr[10]}; // Refresh/init counter. always @(posedge clk or negedge reset_n) begin if (reset_n == 0) refresh_counter <= 20000; else if (refresh_counter == 0) refresh_counter <= 3124; else refresh_counter <= refresh_counter - 1'b1; end // Refresh request signal. always @(posedge clk or negedge reset_n) begin if (reset_n == 0) refresh_request <= 0; else if (1) refresh_request <= ((refresh_counter == 0) | refresh_request) & ~ack_refresh_request & init_done; end // Generate an Interrupt if two ref_reqs occur before one ack_refresh_request always @(posedge clk or negedge reset_n) begin if (reset_n == 0) za_cannotrefresh <= 0; else if (1) za_cannotrefresh <= (refresh_counter == 0) & refresh_request; end // Initialization-done flag. always @(posedge clk or negedge reset_n) begin if (reset_n == 0) init_done <= 0; else if (1) init_done <= init_done | (i_state == 3'b101); end // **** Init FSM **** always @(posedge clk or negedge reset_n) begin if (reset_n == 0) begin i_state <= 3'b000; i_next <= 3'b000; i_cmd <= 4'b1111; i_addr <= {13{1'b1}}; i_count <= {3{1'b0}}; end else begin i_addr <= {13{1'b1}}; case (i_state) // synthesis parallel_case full_case 3'b000: begin i_cmd <= 4'b1111; i_refs <= 3'b0; //Wait for refresh count-down after reset if (refresh_counter == 0) i_state <= 3'b001; end // 3'b000 3'b001: begin i_state <= 3'b011; i_cmd <= {{1{1'b0}},3'h2}; i_count <= 3; i_next <= 3'b010; end // 3'b001 3'b010: begin i_cmd <= {{1{1'b0}},3'h1}; i_refs <= i_refs + 1'b1; i_state <= 3'b011; i_count <= 7; // Count up init_refresh_commands if (i_refs == 3'h7) i_next <= 3'b111; else i_next <= 3'b010; end // 3'b010 3'b011: begin i_cmd <= {{1{1'b0}},3'h7}; //WAIT til safe to Proceed... if (i_count > 1) i_count <= i_count - 1'b1; else i_state <= i_next; end // 3'b011 3'b101: begin i_state <= 3'b101; end // 3'b101 3'b111: begin i_state <= 3'b011; i_cmd <= {{1{1'b0}},3'h0}; i_addr <= {{3{1'b0}},1'b0,2'b00,3'h3,4'h0}; i_count <= 2; i_next <= 3'b101; end // 3'b111 default: begin i_state <= 3'b000; end // default endcase // i_state end end assign active_bank = {active_addr[24],active_addr[10]}; assign csn_match = active_cs_n == f_cs_n; assign rnw_match = active_rnw == f_rnw; assign bank_match = active_bank == f_bank; assign row_match = {active_addr[23 : 11]} == {f_addr[23 : 11]}; assign pending = csn_match && rnw_match && bank_match && row_match && !f_empty; assign cas_addr = f_select ? { {3{1'b0}},f_addr[9 : 0] } : { {3{1'b0}},active_addr[9 : 0] }; // **** Main FSM **** always @(posedge clk or negedge reset_n) begin if (reset_n == 0) begin m_state <= 9'b000000001; m_next <= 9'b000000001; m_cmd <= 4'b1111; m_bank <= 2'b00; m_addr <= 13'b0000000000000; m_data <= 16'b0000000000000000; m_dqm <= 2'b00; m_count <= 3'b000; ack_refresh_request <= 1'b0; f_pop <= 1'b0; oe <= 1'b0; end else begin f_pop <= 1'b0; oe <= 1'b0; case (m_state) // synthesis parallel_case full_case 9'b000000001: begin //Wait for init-fsm to be done... if (init_done) begin //Hold bus if another cycle ended to arf. if (refresh_request) m_cmd <= {{1{1'b0}},3'h7}; else m_cmd <= 4'b1111; ack_refresh_request <= 1'b0; //Wait for a read/write request. if (refresh_request) begin m_state <= 9'b001000000; m_next <= 9'b010000000; m_count <= 3; active_cs_n <= 1'b1; end else if (!f_empty) begin f_pop <= 1'b1; active_cs_n <= f_cs_n; active_rnw <= f_rnw; active_addr <= f_addr; active_data <= f_data; active_dqm <= f_dqm; m_state <= 9'b000000010; end end else begin m_addr <= i_addr; m_state <= 9'b000000001; m_next <= 9'b000000001; m_cmd <= i_cmd; end end // 9'b000000001 9'b000000010: begin m_state <= 9'b000000100; m_cmd <= {csn_decode,3'h3}; m_bank <= active_bank; m_addr <= active_addr[23 : 11]; m_data <= active_data; m_dqm <= active_dqm; m_count <= 4; m_next <= active_rnw ? 9'b000001000 : 9'b000010000; end // 9'b000000010 9'b000000100: begin // precharge all if arf, else precharge csn_decode if (m_next == 9'b010000000) m_cmd <= {{1{1'b0}},3'h7}; else m_cmd <= {csn_decode,3'h7}; //Count down til safe to Proceed... if (m_count > 1) m_count <= m_count - 1'b1; else m_state <= m_next; end // 9'b000000100 9'b000001000: begin m_cmd <= {csn_decode,3'h5}; m_bank <= f_select ? f_bank : active_bank; m_dqm <= f_select ? f_dqm : active_dqm; m_addr <= cas_addr; //Do we have a transaction pending? if (pending) begin //if we need to ARF, bail, else spin if (refresh_request) begin m_state <= 9'b000000100; m_next <= 9'b000000001; m_count <= 2; end else begin f_pop <= 1'b1; active_cs_n <= f_cs_n; active_rnw <= f_rnw; active_addr <= f_addr; active_data <= f_data; active_dqm <= f_dqm; end end else begin //correctly end RD spin cycle if fifo mt if (~pending & f_pop) m_cmd <= {csn_decode,3'h7}; m_state <= 9'b100000000; end end // 9'b000001000 9'b000010000: begin m_cmd <= {csn_decode,3'h4}; oe <= 1'b1; m_data <= f_select ? f_data : active_data; m_dqm <= f_select ? f_dqm : active_dqm; m_bank <= f_select ? f_bank : active_bank; m_addr <= cas_addr; //Do we have a transaction pending? if (pending) begin //if we need to ARF, bail, else spin if (refresh_request) begin m_state <= 9'b000000100; m_next <= 9'b000000001; m_count <= 2; end else begin f_pop <= 1'b1; active_cs_n <= f_cs_n; active_rnw <= f_rnw; active_addr <= f_addr; active_data <= f_data; active_dqm <= f_dqm; end end else begin //correctly end WR spin cycle if fifo empty if (~pending & f_pop) begin m_cmd <= {csn_decode,3'h7}; oe <= 1'b0; end m_state <= 9'b100000000; end end // 9'b000010000 9'b000100000: begin m_cmd <= {csn_decode,3'h7}; //Count down til safe to Proceed... if (m_count > 1) m_count <= m_count - 1'b1; else begin m_state <= 9'b001000000; m_count <= 3; end end // 9'b000100000 9'b001000000: begin m_state <= 9'b000000100; m_addr <= {13{1'b1}}; // precharge all if arf, else precharge csn_decode if (refresh_request) m_cmd <= {{1{1'b0}},3'h2}; else m_cmd <= {csn_decode,3'h2}; end // 9'b001000000 9'b010000000: begin ack_refresh_request <= 1'b1; m_state <= 9'b000000100; m_cmd <= {{1{1'b0}},3'h1}; m_count <= 7; m_next <= 9'b000000001; end // 9'b010000000 9'b100000000: begin m_cmd <= {csn_decode,3'h7}; //if we need to ARF, bail, else spin if (refresh_request) begin m_state <= 9'b000000100; m_next <= 9'b000000001; m_count <= 1; end else //wait for fifo to have contents if (!f_empty) //Are we 'pending' yet? if (csn_match && rnw_match && bank_match && row_match) begin m_state <= f_rnw ? 9'b000001000 : 9'b000010000; f_pop <= 1'b1; active_cs_n <= f_cs_n; active_rnw <= f_rnw; active_addr <= f_addr; active_data <= f_data; active_dqm <= f_dqm; end else begin m_state <= 9'b000100000; m_next <= 9'b000000001; m_count <= 1; end end // 9'b100000000 // synthesis translate_off default: begin m_state <= m_state; m_cmd <= 4'b1111; f_pop <= 1'b0; oe <= 1'b0; end // default // synthesis translate_on endcase // m_state end end assign rd_strobe = m_cmd[2 : 0] == 3'h5; //Track RD Req's based on cas_latency w/shift reg always @(posedge clk or negedge reset_n) begin if (reset_n == 0) rd_valid <= {3{1'b0}}; else rd_valid <= (rd_valid << 1) | { {2{1'b0}}, rd_strobe }; end // Register dq data. always @(posedge clk or negedge reset_n) begin if (reset_n == 0) za_data <= 0; else za_data <= zs_dq; end // Delay za_valid to match registered data. always @(posedge clk or negedge reset_n) begin if (reset_n == 0) za_valid <= 0; else if (1) za_valid <= rd_valid[2]; end assign cmd_code = m_cmd[2 : 0]; assign cmd_all = m_cmd; //synthesis translate_off //////////////// SIMULATION-ONLY CONTENTS initial begin $write("\n"); $write("This reference design requires a vendor simulation model.\n"); $write("To simulate accesses to SDRAM, you must:\n"); $write(" - Download the vendor model\n"); $write(" - Install the model in the system_sim directory\n"); $write(" - `include the vendor model in the the top-level system file,\n"); $write(" - Instantiate sdram simulation models and wire them to testbench signals\n"); $write(" - Be aware that you may have to disable some timing checks in the vendor model\n"); $write(" (because this simulation is zero-delay based)\n"); $write("\n"); end assign txt_code = (cmd_code == 3'h0)? 24'h4c4d52 : (cmd_code == 3'h1)? 24'h415246 : (cmd_code == 3'h2)? 24'h505245 : (cmd_code == 3'h3)? 24'h414354 : (cmd_code == 3'h4)? 24'h205752 : (cmd_code == 3'h5)? 24'h205244 : (cmd_code == 3'h6)? 24'h425354 : (cmd_code == 3'h7)? 24'h4e4f50 : 24'h424144; assign CODE = &(cmd_all|4'h7) ? 24'h494e48 : txt_code; //////////////// END SIMULATION-ONLY CONTENTS //synthesis translate_on endmodule
//Legal Notice: (C)2017 Altera Corporation. All rights reserved. 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 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. // synthesis translate_off `timescale 1ns / 1ps // synthesis translate_on // turn off superfluous verilog processor warnings // altera message_level Level1 // altera message_off 10034 10035 10036 10037 10230 10240 10030 module soc_design_SDRAM_input_efifo_module ( // inputs: clk, rd, reset_n, wr, wr_data, // outputs: almost_empty, almost_full, empty, full, rd_data ) ; output almost_empty; output almost_full; output empty; output full; output [ 43: 0] rd_data; input clk; input rd; input reset_n; input wr; input [ 43: 0] wr_data; wire almost_empty; wire almost_full; wire empty; reg [ 1: 0] entries; reg [ 43: 0] entry_0; reg [ 43: 0] entry_1; wire full; reg rd_address; reg [ 43: 0] rd_data; wire [ 1: 0] rdwr; reg wr_address; assign rdwr = {rd, wr}; assign full = entries == 2; assign almost_full = entries >= 1; assign empty = entries == 0; assign almost_empty = entries <= 1; always @(entry_0 or entry_1 or rd_address) begin case (rd_address) // synthesis parallel_case full_case 1'd0: begin rd_data = entry_0; end // 1'd0 1'd1: begin rd_data = entry_1; end // 1'd1 default: begin end // default endcase // rd_address end always @(posedge clk or negedge reset_n) begin if (reset_n == 0) begin wr_address <= 0; rd_address <= 0; entries <= 0; end else case (rdwr) // synthesis parallel_case full_case 2'd1: begin // Write data if (!full) begin entries <= entries + 1; wr_address <= (wr_address == 1) ? 0 : (wr_address + 1); end end // 2'd1 2'd2: begin // Read data if (!empty) begin entries <= entries - 1; rd_address <= (rd_address == 1) ? 0 : (rd_address + 1); end end // 2'd2 2'd3: begin wr_address <= (wr_address == 1) ? 0 : (wr_address + 1); rd_address <= (rd_address == 1) ? 0 : (rd_address + 1); end // 2'd3 default: begin end // default endcase // rdwr end always @(posedge clk) begin //Write data if (wr & !full) case (wr_address) // synthesis parallel_case full_case 1'd0: begin entry_0 <= wr_data; end // 1'd0 1'd1: begin entry_1 <= wr_data; end // 1'd1 default: begin end // default endcase // wr_address end endmodule // synthesis translate_off `timescale 1ns / 1ps // synthesis translate_on // turn off superfluous verilog processor warnings // altera message_level Level1 // altera message_off 10034 10035 10036 10037 10230 10240 10030 module soc_design_SDRAM ( // inputs: az_addr, az_be_n, az_cs, az_data, az_rd_n, az_wr_n, clk, reset_n, // outputs: za_data, za_valid, za_waitrequest, zs_addr, zs_ba, zs_cas_n, zs_cke, zs_cs_n, zs_dq, zs_dqm, zs_ras_n, zs_we_n ) ; output [ 15: 0] za_data; output za_valid; output za_waitrequest; output [ 12: 0] zs_addr; output [ 1: 0] zs_ba; output zs_cas_n; output zs_cke; output zs_cs_n; inout [ 15: 0] zs_dq; output [ 1: 0] zs_dqm; output zs_ras_n; output zs_we_n; input [ 24: 0] az_addr; input [ 1: 0] az_be_n; input az_cs; input [ 15: 0] az_data; input az_rd_n; input az_wr_n; input clk; input reset_n; wire [ 23: 0] CODE; reg ack_refresh_request; reg [ 24: 0] active_addr; wire [ 1: 0] active_bank; reg active_cs_n; reg [ 15: 0] active_data; reg [ 1: 0] active_dqm; reg active_rnw; wire almost_empty; wire almost_full; wire bank_match; wire [ 9: 0] cas_addr; wire clk_en; wire [ 3: 0] cmd_all; wire [ 2: 0] cmd_code; wire cs_n; wire csn_decode; wire csn_match; wire [ 24: 0] f_addr; wire [ 1: 0] f_bank; wire f_cs_n; wire [ 15: 0] f_data; wire [ 1: 0] f_dqm; wire f_empty; reg f_pop; wire f_rnw; wire f_select; wire [ 43: 0] fifo_read_data; reg [ 12: 0] i_addr; reg [ 3: 0] i_cmd; reg [ 2: 0] i_count; reg [ 2: 0] i_next; reg [ 2: 0] i_refs; reg [ 2: 0] i_state; reg init_done; reg [ 12: 0] m_addr /* synthesis ALTERA_ATTRIBUTE = "FAST_OUTPUT_REGISTER=ON" */; reg [ 1: 0] m_bank /* synthesis ALTERA_ATTRIBUTE = "FAST_OUTPUT_REGISTER=ON" */; reg [ 3: 0] m_cmd /* synthesis ALTERA_ATTRIBUTE = "FAST_OUTPUT_REGISTER=ON" */; reg [ 2: 0] m_count; reg [ 15: 0] m_data /* synthesis ALTERA_ATTRIBUTE = "FAST_OUTPUT_REGISTER=ON ; FAST_OUTPUT_ENABLE_REGISTER=ON" */; reg [ 1: 0] m_dqm /* synthesis ALTERA_ATTRIBUTE = "FAST_OUTPUT_REGISTER=ON" */; reg [ 8: 0] m_next; reg [ 8: 0] m_state; reg oe /* synthesis ALTERA_ATTRIBUTE = "FAST_OUTPUT_ENABLE_REGISTER=ON" */; wire pending; wire rd_strobe; reg [ 2: 0] rd_valid; reg [ 14: 0] refresh_counter; reg refresh_request; wire rnw_match; wire row_match; wire [ 23: 0] txt_code; reg za_cannotrefresh; reg [ 15: 0] za_data /* synthesis ALTERA_ATTRIBUTE = "FAST_INPUT_REGISTER=ON" */; reg za_valid; wire za_waitrequest; wire [ 12: 0] zs_addr; wire [ 1: 0] zs_ba; wire zs_cas_n; wire zs_cke; wire zs_cs_n; wire [ 15: 0] zs_dq; wire [ 1: 0] zs_dqm; wire zs_ras_n; wire zs_we_n; assign clk_en = 1; //s1, which is an e_avalon_slave assign {zs_cs_n, zs_ras_n, zs_cas_n, zs_we_n} = m_cmd; assign zs_addr = m_addr; assign zs_cke = clk_en; assign zs_dq = oe?m_data:{16{1'bz}}; assign zs_dqm = m_dqm; assign zs_ba = m_bank; assign f_select = f_pop & pending; assign f_cs_n = 1'b0; assign cs_n = f_select ? f_cs_n : active_cs_n; assign csn_decode = cs_n; assign {f_rnw, f_addr, f_dqm, f_data} = fifo_read_data; soc_design_SDRAM_input_efifo_module the_soc_design_SDRAM_input_efifo_module ( .almost_empty (almost_empty), .almost_full (almost_full), .clk (clk), .empty (f_empty), .full (za_waitrequest), .rd (f_select), .rd_data (fifo_read_data), .reset_n (reset_n), .wr ((~az_wr_n | ~az_rd_n) & !za_waitrequest), .wr_data ({az_wr_n, az_addr, az_wr_n ? 2'b0 : az_be_n, az_data}) ); assign f_bank = {f_addr[24],f_addr[10]}; // Refresh/init counter. always @(posedge clk or negedge reset_n) begin if (reset_n == 0) refresh_counter <= 20000; else if (refresh_counter == 0) refresh_counter <= 3124; else refresh_counter <= refresh_counter - 1'b1; end // Refresh request signal. always @(posedge clk or negedge reset_n) begin if (reset_n == 0) refresh_request <= 0; else if (1) refresh_request <= ((refresh_counter == 0) | refresh_request) & ~ack_refresh_request & init_done; end // Generate an Interrupt if two ref_reqs occur before one ack_refresh_request always @(posedge clk or negedge reset_n) begin if (reset_n == 0) za_cannotrefresh <= 0; else if (1) za_cannotrefresh <= (refresh_counter == 0) & refresh_request; end // Initialization-done flag. always @(posedge clk or negedge reset_n) begin if (reset_n == 0) init_done <= 0; else if (1) init_done <= init_done | (i_state == 3'b101); end // **** Init FSM **** always @(posedge clk or negedge reset_n) begin if (reset_n == 0) begin i_state <= 3'b000; i_next <= 3'b000; i_cmd <= 4'b1111; i_addr <= {13{1'b1}}; i_count <= {3{1'b0}}; end else begin i_addr <= {13{1'b1}}; case (i_state) // synthesis parallel_case full_case 3'b000: begin i_cmd <= 4'b1111; i_refs <= 3'b0; //Wait for refresh count-down after reset if (refresh_counter == 0) i_state <= 3'b001; end // 3'b000 3'b001: begin i_state <= 3'b011; i_cmd <= {{1{1'b0}},3'h2}; i_count <= 3; i_next <= 3'b010; end // 3'b001 3'b010: begin i_cmd <= {{1{1'b0}},3'h1}; i_refs <= i_refs + 1'b1; i_state <= 3'b011; i_count <= 7; // Count up init_refresh_commands if (i_refs == 3'h7) i_next <= 3'b111; else i_next <= 3'b010; end // 3'b010 3'b011: begin i_cmd <= {{1{1'b0}},3'h7}; //WAIT til safe to Proceed... if (i_count > 1) i_count <= i_count - 1'b1; else i_state <= i_next; end // 3'b011 3'b101: begin i_state <= 3'b101; end // 3'b101 3'b111: begin i_state <= 3'b011; i_cmd <= {{1{1'b0}},3'h0}; i_addr <= {{3{1'b0}},1'b0,2'b00,3'h3,4'h0}; i_count <= 2; i_next <= 3'b101; end // 3'b111 default: begin i_state <= 3'b000; end // default endcase // i_state end end assign active_bank = {active_addr[24],active_addr[10]}; assign csn_match = active_cs_n == f_cs_n; assign rnw_match = active_rnw == f_rnw; assign bank_match = active_bank == f_bank; assign row_match = {active_addr[23 : 11]} == {f_addr[23 : 11]}; assign pending = csn_match && rnw_match && bank_match && row_match && !f_empty; assign cas_addr = f_select ? { {3{1'b0}},f_addr[9 : 0] } : { {3{1'b0}},active_addr[9 : 0] }; // **** Main FSM **** always @(posedge clk or negedge reset_n) begin if (reset_n == 0) begin m_state <= 9'b000000001; m_next <= 9'b000000001; m_cmd <= 4'b1111; m_bank <= 2'b00; m_addr <= 13'b0000000000000; m_data <= 16'b0000000000000000; m_dqm <= 2'b00; m_count <= 3'b000; ack_refresh_request <= 1'b0; f_pop <= 1'b0; oe <= 1'b0; end else begin f_pop <= 1'b0; oe <= 1'b0; case (m_state) // synthesis parallel_case full_case 9'b000000001: begin //Wait for init-fsm to be done... if (init_done) begin //Hold bus if another cycle ended to arf. if (refresh_request) m_cmd <= {{1{1'b0}},3'h7}; else m_cmd <= 4'b1111; ack_refresh_request <= 1'b0; //Wait for a read/write request. if (refresh_request) begin m_state <= 9'b001000000; m_next <= 9'b010000000; m_count <= 3; active_cs_n <= 1'b1; end else if (!f_empty) begin f_pop <= 1'b1; active_cs_n <= f_cs_n; active_rnw <= f_rnw; active_addr <= f_addr; active_data <= f_data; active_dqm <= f_dqm; m_state <= 9'b000000010; end end else begin m_addr <= i_addr; m_state <= 9'b000000001; m_next <= 9'b000000001; m_cmd <= i_cmd; end end // 9'b000000001 9'b000000010: begin m_state <= 9'b000000100; m_cmd <= {csn_decode,3'h3}; m_bank <= active_bank; m_addr <= active_addr[23 : 11]; m_data <= active_data; m_dqm <= active_dqm; m_count <= 4; m_next <= active_rnw ? 9'b000001000 : 9'b000010000; end // 9'b000000010 9'b000000100: begin // precharge all if arf, else precharge csn_decode if (m_next == 9'b010000000) m_cmd <= {{1{1'b0}},3'h7}; else m_cmd <= {csn_decode,3'h7}; //Count down til safe to Proceed... if (m_count > 1) m_count <= m_count - 1'b1; else m_state <= m_next; end // 9'b000000100 9'b000001000: begin m_cmd <= {csn_decode,3'h5}; m_bank <= f_select ? f_bank : active_bank; m_dqm <= f_select ? f_dqm : active_dqm; m_addr <= cas_addr; //Do we have a transaction pending? if (pending) begin //if we need to ARF, bail, else spin if (refresh_request) begin m_state <= 9'b000000100; m_next <= 9'b000000001; m_count <= 2; end else begin f_pop <= 1'b1; active_cs_n <= f_cs_n; active_rnw <= f_rnw; active_addr <= f_addr; active_data <= f_data; active_dqm <= f_dqm; end end else begin //correctly end RD spin cycle if fifo mt if (~pending & f_pop) m_cmd <= {csn_decode,3'h7}; m_state <= 9'b100000000; end end // 9'b000001000 9'b000010000: begin m_cmd <= {csn_decode,3'h4}; oe <= 1'b1; m_data <= f_select ? f_data : active_data; m_dqm <= f_select ? f_dqm : active_dqm; m_bank <= f_select ? f_bank : active_bank; m_addr <= cas_addr; //Do we have a transaction pending? if (pending) begin //if we need to ARF, bail, else spin if (refresh_request) begin m_state <= 9'b000000100; m_next <= 9'b000000001; m_count <= 2; end else begin f_pop <= 1'b1; active_cs_n <= f_cs_n; active_rnw <= f_rnw; active_addr <= f_addr; active_data <= f_data; active_dqm <= f_dqm; end end else begin //correctly end WR spin cycle if fifo empty if (~pending & f_pop) begin m_cmd <= {csn_decode,3'h7}; oe <= 1'b0; end m_state <= 9'b100000000; end end // 9'b000010000 9'b000100000: begin m_cmd <= {csn_decode,3'h7}; //Count down til safe to Proceed... if (m_count > 1) m_count <= m_count - 1'b1; else begin m_state <= 9'b001000000; m_count <= 3; end end // 9'b000100000 9'b001000000: begin m_state <= 9'b000000100; m_addr <= {13{1'b1}}; // precharge all if arf, else precharge csn_decode if (refresh_request) m_cmd <= {{1{1'b0}},3'h2}; else m_cmd <= {csn_decode,3'h2}; end // 9'b001000000 9'b010000000: begin ack_refresh_request <= 1'b1; m_state <= 9'b000000100; m_cmd <= {{1{1'b0}},3'h1}; m_count <= 7; m_next <= 9'b000000001; end // 9'b010000000 9'b100000000: begin m_cmd <= {csn_decode,3'h7}; //if we need to ARF, bail, else spin if (refresh_request) begin m_state <= 9'b000000100; m_next <= 9'b000000001; m_count <= 1; end else //wait for fifo to have contents if (!f_empty) //Are we 'pending' yet? if (csn_match && rnw_match && bank_match && row_match) begin m_state <= f_rnw ? 9'b000001000 : 9'b000010000; f_pop <= 1'b1; active_cs_n <= f_cs_n; active_rnw <= f_rnw; active_addr <= f_addr; active_data <= f_data; active_dqm <= f_dqm; end else begin m_state <= 9'b000100000; m_next <= 9'b000000001; m_count <= 1; end end // 9'b100000000 // synthesis translate_off default: begin m_state <= m_state; m_cmd <= 4'b1111; f_pop <= 1'b0; oe <= 1'b0; end // default // synthesis translate_on endcase // m_state end end assign rd_strobe = m_cmd[2 : 0] == 3'h5; //Track RD Req's based on cas_latency w/shift reg always @(posedge clk or negedge reset_n) begin if (reset_n == 0) rd_valid <= {3{1'b0}}; else rd_valid <= (rd_valid << 1) | { {2{1'b0}}, rd_strobe }; end // Register dq data. always @(posedge clk or negedge reset_n) begin if (reset_n == 0) za_data <= 0; else za_data <= zs_dq; end // Delay za_valid to match registered data. always @(posedge clk or negedge reset_n) begin if (reset_n == 0) za_valid <= 0; else if (1) za_valid <= rd_valid[2]; end assign cmd_code = m_cmd[2 : 0]; assign cmd_all = m_cmd; //synthesis translate_off //////////////// SIMULATION-ONLY CONTENTS initial begin $write("\n"); $write("This reference design requires a vendor simulation model.\n"); $write("To simulate accesses to SDRAM, you must:\n"); $write(" - Download the vendor model\n"); $write(" - Install the model in the system_sim directory\n"); $write(" - `include the vendor model in the the top-level system file,\n"); $write(" - Instantiate sdram simulation models and wire them to testbench signals\n"); $write(" - Be aware that you may have to disable some timing checks in the vendor model\n"); $write(" (because this simulation is zero-delay based)\n"); $write("\n"); end assign txt_code = (cmd_code == 3'h0)? 24'h4c4d52 : (cmd_code == 3'h1)? 24'h415246 : (cmd_code == 3'h2)? 24'h505245 : (cmd_code == 3'h3)? 24'h414354 : (cmd_code == 3'h4)? 24'h205752 : (cmd_code == 3'h5)? 24'h205244 : (cmd_code == 3'h6)? 24'h425354 : (cmd_code == 3'h7)? 24'h4e4f50 : 24'h424144; assign CODE = &(cmd_all|4'h7) ? 24'h494e48 : txt_code; //////////////// END SIMULATION-ONLY CONTENTS //synthesis translate_on endmodule
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * 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. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // 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 REGENTS OF THE // UNIVERSITY OF CALIFORNIA 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. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: rxc_engine_classic.v // Version: 1.0 // Verilog Standard: Verilog-2001 // Description: The RXC Engine (Classic) takes a single stream of TLP // packets and provides the completion packets on the RXC Interface. // This Engine is capable of operating at "line rate". // Author: Dustin Richmond (@darichmond) //----------------------------------------------------------------------------- `timescale 1ns/1ns `include "trellis.vh" `include "tlp.vh" module rxc_engine_classic #(parameter C_VENDOR = "ALTERA", parameter C_PCI_DATA_WIDTH = 128, parameter C_RX_PIPELINE_DEPTH = 10) (// Interface: Clocks input CLK, // Interface: Resets input RST_BUS, // Replacement for generic RST_IN input RST_LOGIC, // Addition for RIFFA_RST output DONE_RXC_RST, // Interface: RX Classic input [C_PCI_DATA_WIDTH-1:0] RX_TLP, input RX_TLP_VALID, input RX_TLP_START_FLAG, input [`SIG_OFFSET_W-1:0] RX_TLP_START_OFFSET, input RX_TLP_END_FLAG, input [`SIG_OFFSET_W-1:0] RX_TLP_END_OFFSET, input [`SIG_BARDECODE_W-1:0] RX_TLP_BAR_DECODE, // Interface: RXC Engine output [C_PCI_DATA_WIDTH-1:0] RXC_DATA, output RXC_DATA_VALID, output [(C_PCI_DATA_WIDTH/32)-1:0] RXC_DATA_WORD_ENABLE, output RXC_DATA_START_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] RXC_DATA_START_OFFSET, output RXC_DATA_END_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] RXC_DATA_END_OFFSET, output [`SIG_LBE_W-1:0] RXC_META_LDWBE, output [`SIG_FBE_W-1:0] RXC_META_FDWBE, output [`SIG_TAG_W-1:0] RXC_META_TAG, output [`SIG_LOWADDR_W-1:0] RXC_META_ADDR, output [`SIG_TYPE_W-1:0] RXC_META_TYPE, output [`SIG_LEN_W-1:0] RXC_META_LENGTH, output [`SIG_BYTECNT_W-1:0] RXC_META_BYTES_REMAINING, output [`SIG_CPLID_W-1:0] RXC_META_COMPLETER_ID, output RXC_META_EP, // Interface: RX Shift Register input [(C_RX_PIPELINE_DEPTH+1)*C_PCI_DATA_WIDTH-1:0] RX_SR_DATA, input [C_RX_PIPELINE_DEPTH:0] RX_SR_EOP, input [(C_RX_PIPELINE_DEPTH+1)*`SIG_OFFSET_W-1:0] RX_SR_END_OFFSET, input [C_RX_PIPELINE_DEPTH:0] RX_SR_SOP, input [C_RX_PIPELINE_DEPTH:0] RX_SR_VALID); /*AUTOWIRE*/ /*AUTOINPUT*/ ///*AUTOOUTPUT*/ // End of automatics localparam C_RX_BE_W = (`SIG_FBE_W+`SIG_LBE_W); localparam C_RX_INPUT_STAGES = 1; localparam C_RX_OUTPUT_STAGES = 1; // Must always be at least one localparam C_RX_COMPUTATION_STAGES = 1; localparam C_RX_DATA_STAGES = C_RX_COMPUTATION_STAGES; localparam C_RX_META_STAGES = C_RX_DATA_STAGES - 1; localparam C_TOTAL_STAGES = C_RX_COMPUTATION_STAGES + C_RX_OUTPUT_STAGES + C_RX_INPUT_STAGES; // Cycle index in the SOP register when enable is raised // Computation can begin when the last DW of the header is recieved. localparam C_RX_COMPUTATION_CYCLE = C_RX_COMPUTATION_STAGES + (`TLP_CPLMETADW2_I/C_PCI_DATA_WIDTH); // The computation cycle must be at least one cycle before the address is enabled localparam C_RX_DATA_CYCLE = C_RX_COMPUTATION_CYCLE; localparam C_RX_METADW0_CYCLE = (`TLP_CPLMETADW0_I/C_PCI_DATA_WIDTH) + C_RX_INPUT_STAGES; localparam C_RX_METADW1_CYCLE = (`TLP_CPLMETADW1_I/C_PCI_DATA_WIDTH) + C_RX_INPUT_STAGES; localparam C_RX_METADW2_CYCLE = (`TLP_CPLMETADW2_I/C_PCI_DATA_WIDTH) + C_RX_INPUT_STAGES; localparam C_RX_METADW0_INDEX = C_PCI_DATA_WIDTH*C_RX_INPUT_STAGES + (`TLP_CPLMETADW0_I%C_PCI_DATA_WIDTH); localparam C_RX_METADW1_INDEX = C_PCI_DATA_WIDTH*C_RX_INPUT_STAGES + (`TLP_CPLMETADW1_I%C_PCI_DATA_WIDTH); localparam C_RX_METADW2_INDEX = C_PCI_DATA_WIDTH*C_RX_INPUT_STAGES + (`TLP_CPLMETADW2_I%C_PCI_DATA_WIDTH); localparam C_OFFSET_WIDTH = clog2s(C_PCI_DATA_WIDTH/32); localparam C_MAX_ABLANK_WIDTH = 32; localparam C_MAX_START_OFFSET = (`TLP_MAXHDR_W + C_MAX_ABLANK_WIDTH)/32; localparam C_STD_START_DELAY = (64/C_PCI_DATA_WIDTH); wire [`TLP_CPLADDR_W-1:0] wAddr; wire [`TLP_CPLHDR_W-1:0] wMetadata; wire [`TLP_TYPE_W-1:0] wType; wire [`TLP_LEN_W-1:0] wLength; wire [2:0] wHdrLength; wire [2:0] wHdrLengthM1; wire [(C_PCI_DATA_WIDTH/32)-1:0] wEndMask; wire wEndFlag; wire [clog2s(C_PCI_DATA_WIDTH/32)-1:0] wEndOffset; wire [(C_PCI_DATA_WIDTH/32)-1:0] wStartMask; wire wStartFlag; wire _wStartFlag; wire [2:0] wStartOffset; wire [3:0] wStartFlags; wire wInsertBlank; wire [C_PCI_DATA_WIDTH-1:0] wRxcData; wire [95:0] wRxcMetadata; wire wRxcDataValid; wire wRxcDataEndFlag; wire [clog2s(C_PCI_DATA_WIDTH/32)-1:0] wRxcDataEndOffset; wire wRxcDataStartFlag; wire [clog2s(C_PCI_DATA_WIDTH/32)-1:0] wRxcDataStartOffset; wire [(C_PCI_DATA_WIDTH/32)-1:0] wRxcDataWordEnable; wire [C_RX_PIPELINE_DEPTH:0] wRxSrSop; reg rValid,_rValid; reg rRST; assign DONE_RXC_RST = ~rRST; // Calculate the header length (start offset), and header length minus 1 (end offset) assign wHdrLength = 3'b011; assign wHdrLengthM1 = 3'b010; // Determine if the TLP has an inserted blank before the payload assign wInsertBlank = ~wAddr[2] & (C_VENDOR == "ALTERA"); assign wStartOffset = (wHdrLength + {2'd0,wInsertBlank}); // Start offset in dwords assign wEndOffset = wHdrLengthM1 + wInsertBlank + wLength; //RX_SR_END_OFFSET[(C_TOTAL_STAGES-1)*`SIG_OFFSET_W +: C_OFFSET_WIDTH]; // Outputs assign RXC_DATA = RX_SR_DATA[(C_TOTAL_STAGES)*C_PCI_DATA_WIDTH +: C_PCI_DATA_WIDTH]; assign RXC_DATA_VALID = wRxcDataValid; assign RXC_DATA_END_FLAG = wRxcDataEndFlag; assign RXC_DATA_END_OFFSET = wRxcDataEndOffset; assign RXC_DATA_START_FLAG = wRxcDataStartFlag; assign RXC_DATA_START_OFFSET = wRxcDataStartOffset; assign RXC_META_LENGTH = wRxcMetadata[`TLP_LEN_R]; //assign RXC_META_TC = wRxcMetadata[`TLP_TC_R]; //assign RXC_META_ATTR = {wRxcMetadata[`TLP_ATTR1_R], wRxcMetadata[`TLP_ATTR0_R]}; assign RXC_META_TYPE = tlp_to_trellis_type({wRxcMetadata[`TLP_FMT_R],wRxcMetadata[`TLP_TYPE_R]}); assign RXC_META_ADDR = wRxcMetadata[`TLP_CPLADDR_R]; assign RXC_META_COMPLETER_ID = wRxcMetadata[`TLP_CPLCPLID_R]; assign RXC_META_BYTES_REMAINING = wRxcMetadata[`TLP_CPLBYTECNT_R]; assign RXC_META_TAG = wRxcMetadata[`TLP_CPLTAG_R]; assign RXC_META_EP = wRxcMetadata[`TLP_EP_R]; assign RXC_META_FDWBE = 0;// TODO: Remove (use addr) assign RXC_META_LDWBE = 0;// TODO: Remove (use addr) assign wEndFlag = RX_SR_EOP[C_RX_INPUT_STAGES+1]; assign _wStartFlag = wStartFlags != 0; generate if(C_PCI_DATA_WIDTH == 32) begin assign wStartFlags[3] = 0; assign wStartFlags[2] = wRxSrSop[C_RX_INPUT_STAGES + 3] & wMetadata[`TLP_PAYBIT_I] & ~rValid; // Any remaining cases assign wStartFlags[1] = wRxSrSop[C_RX_INPUT_STAGES + 2] & wMetadata[`TLP_PAYBIT_I] & ~wMetadata[`TLP_4DWHBIT_I]; // 3DWH, No Blank assign wStartFlags[0] = wRxSrSop[C_RX_INPUT_STAGES + 2] & ~wMetadata[`TLP_PAYBIT_I]; // No Payload end else if(C_PCI_DATA_WIDTH == 64) begin assign wStartFlags[3] = 0; assign wStartFlags[2] = wRxSrSop[C_RX_INPUT_STAGES + 2] & wMetadata[`TLP_PAYBIT_I] & ~rValid; // Any remaining cases if(C_VENDOR == "ALTERA") begin assign wStartFlags[1] = wRxSrSop[C_RX_INPUT_STAGES + 1] & wMetadata[`TLP_PAYBIT_I] & ~wMetadata[`TLP_4DWHBIT_I] & RX_SR_DATA[C_RX_METADW2_INDEX + 2]; // 3DWH, No Blank end else begin assign wStartFlags[1] = wRxSrSop[C_RX_INPUT_STAGES + 1] & wMetadata[`TLP_PAYBIT_I] & ~wMetadata[`TLP_4DWHBIT_I]; // 3DWH, No Blank end assign wStartFlags[0] = wRxSrSop[C_RX_INPUT_STAGES + 1] & ~wMetadata[`TLP_PAYBIT_I] & rValid; // No Payload end else if (C_PCI_DATA_WIDTH == 128) begin assign wStartFlags[3] = 0; assign wStartFlags[2] = wRxSrSop[C_RX_INPUT_STAGES + 1] & wMetadata[`TLP_PAYBIT_I] & ~rValid; // Is this correct? if(C_VENDOR == "ALTERA") begin assign wStartFlags[1] = wRxSrSop[C_RX_INPUT_STAGES] & RX_SR_DATA[C_RX_METADW0_INDEX + `TLP_PAYBIT_I] & ~RX_SR_DATA[C_RX_METADW0_INDEX + `TLP_4DWHBIT_I] & RX_SR_DATA[C_RX_METADW2_INDEX + 2]; // 3DWH, No Blank end else begin assign wStartFlags[1] = wRxSrSop[C_RX_INPUT_STAGES] & RX_SR_DATA[C_RX_METADW0_INDEX + `TLP_PAYBIT_I] & ~RX_SR_DATA[C_RX_METADW0_INDEX + `TLP_4DWHBIT_I]; end assign wStartFlags[0] = wRxSrSop[C_RX_INPUT_STAGES] & ~RX_SR_DATA[C_RX_METADW0_INDEX + `TLP_PAYBIT_I]; // No Payload end else begin // 256 assign wStartFlags[3] = 0; assign wStartFlags[2] = 0; assign wStartFlags[1] = 0; assign wStartFlags[0] = wRxSrSop[C_RX_INPUT_STAGES]; end // else: !if(C_PCI_DATA_WIDTH == 128) endgenerate always @(*) begin _rValid = rValid; if(_wStartFlag) begin _rValid = 1'b1; end else if (RX_SR_EOP[C_RX_INPUT_STAGES+1]) begin _rValid = 1'b0; end end always @(posedge CLK) begin if(rRST) begin rValid <= 1'b0; end else begin rValid <= _rValid; end end always @(posedge CLK) begin rRST <= RST_BUS | RST_LOGIC; end register #(// Parameters .C_WIDTH (32)) metadata_DW0_register (// Outputs .RD_DATA (wMetadata[31:0]), // Inputs .RST_IN (0), .WR_DATA (RX_SR_DATA[C_RX_METADW0_INDEX +: 32]), .WR_EN (wRxSrSop[C_RX_METADW0_CYCLE]), /*AUTOINST*/ // Inputs .CLK (CLK)); register #(// Parameters .C_WIDTH (32)) meta_DW1_register (// Outputs .RD_DATA (wMetadata[63:32]), // Inputs .RST_IN (0), .WR_DATA (RX_SR_DATA[C_RX_METADW1_INDEX +: 32]), .WR_EN (wRxSrSop[C_RX_METADW1_CYCLE]), /*AUTOINST*/ // Inputs .CLK (CLK)); register #(// Parameters .C_WIDTH (32)) meta_DW2_register (// Outputs .RD_DATA (wMetadata[95:64]), // Inputs .RST_IN (0), .WR_DATA (RX_SR_DATA[C_RX_METADW2_INDEX +: 32]), .WR_EN (wRxSrSop[C_RX_METADW2_CYCLE]), /*AUTOINST*/ // Inputs .CLK (CLK)); register #(// Parameters .C_WIDTH (`TLP_TYPE_W)) metadata_type_register (// Outputs .RD_DATA (wType), // Inputs .RST_IN (0), .WR_DATA (RX_SR_DATA[(`TLP_TYPE_I + C_PCI_DATA_WIDTH*C_RX_INPUT_STAGES) +: `TLP_TYPE_W]), .WR_EN (wRxSrSop[`TLP_TYPE_I/C_PCI_DATA_WIDTH + C_RX_INPUT_STAGES]), /*AUTOINST*/ // Inputs .CLK (CLK)); register #(// Parameters .C_WIDTH (`TLP_LEN_W)) metadata_length_register (// Outputs .RD_DATA (wLength), // Inputs .RST_IN (0), .WR_DATA (RX_SR_DATA[((`TLP_LEN_I%C_PCI_DATA_WIDTH) + C_PCI_DATA_WIDTH*C_RX_INPUT_STAGES) +: `TLP_LEN_W]), .WR_EN (wRxSrSop[`TLP_LEN_I/C_PCI_DATA_WIDTH + C_RX_INPUT_STAGES]), /*AUTOINST*/ // Inputs .CLK (CLK)); register #(// Parameters .C_WIDTH (`TLP_CPLADDR_W)) metadata_address_register (// Outputs .RD_DATA (wAddr), // Inputs .RST_IN (0), .WR_DATA (RX_SR_DATA[((`TLP_CPLADDR_I%C_PCI_DATA_WIDTH) + C_PCI_DATA_WIDTH*C_RX_INPUT_STAGES) +: `TLP_CPLADDR_W]), .WR_EN (wRxSrSop[`TLP_CPLADDR_I/C_PCI_DATA_WIDTH + C_RX_INPUT_STAGES]), /*AUTOINST*/ // Inputs .CLK (CLK)); register #(// Parameters .C_WIDTH (1), .C_VALUE (1'b0) /*AUTOINSTPARAM*/) start_flag_register (// Outputs .RD_DATA (wStartFlag), // Inputs .RST_IN (0), .WR_DATA (_wStartFlag), .WR_EN (1), /*AUTOINST*/ // Inputs .CLK (CLK)); assign wStartMask = {C_PCI_DATA_WIDTH/32{1'b1}} << ({C_OFFSET_WIDTH{wStartFlag}}& wStartOffset[C_OFFSET_WIDTH-1:0]); offset_to_mask #(// Parameters .C_MASK_SWAP (0), .C_MASK_WIDTH (C_PCI_DATA_WIDTH/32) /*AUTOINSTPARAM*/) o2m_ef (// Outputs .MASK (wEndMask), // Inputs .OFFSET_ENABLE (wEndFlag), .OFFSET (wEndOffset) /*AUTOINST*/); generate if(C_RX_OUTPUT_STAGES == 0) begin assign RXC_DATA_WORD_ENABLE = {wEndMask & wStartMask} & {C_PCI_DATA_WIDTH/32{~rValid | ~wMetadata[`TLP_PAYBIT_I]}}; end else begin register #(// Parameters .C_WIDTH (C_PCI_DATA_WIDTH/32), .C_VALUE (0) /*AUTOINSTPARAM*/) dw_enable (// Outputs .RD_DATA (wRxcDataWordEnable), // Inputs .RST_IN (~rValid | ~wMetadata[`TLP_PAYBIT_I]), .WR_DATA (wEndMask & wStartMask), .WR_EN (1), /*AUTOINST*/ // Inputs .CLK (CLK)); pipeline #(// Parameters .C_DEPTH (C_RX_OUTPUT_STAGES-1), .C_WIDTH (C_PCI_DATA_WIDTH/32), .C_USE_MEMORY (0) /*AUTOINSTPARAM*/) dw_pipeline (// Outputs .WR_DATA_READY (), // Pinned to 1 .RD_DATA (RXC_DATA_WORD_ENABLE), .RD_DATA_VALID (), // Inputs .WR_DATA (wRxcDataWordEnable), .WR_DATA_VALID (1), .RD_DATA_READY (1'b1), .RST_IN (rRST), /*AUTOINST*/ // Inputs .CLK (CLK)); end endgenerate pipeline #(// Parameters .C_DEPTH (C_RX_OUTPUT_STAGES), .C_WIDTH (`TLP_CPLHDR_W + 2*(clog2s(C_PCI_DATA_WIDTH/32) + 1)), .C_USE_MEMORY (0) /*AUTOINSTPARAM*/) output_pipeline (// Outputs .WR_DATA_READY (), // Pinned to 1 .RD_DATA ({wRxcMetadata,wRxcDataStartFlag,wRxcDataStartOffset,wRxcDataEndFlag,wRxcDataEndOffset}), .RD_DATA_VALID (wRxcDataValid), // Inputs .WR_DATA ({wMetadata, wStartFlag,wStartOffset[C_OFFSET_WIDTH-1:0],wEndFlag,wEndOffset[C_OFFSET_WIDTH-1:0]}), .WR_DATA_VALID (rValid & RX_SR_VALID[C_TOTAL_STAGES - C_RX_OUTPUT_STAGES]), .RD_DATA_READY (1'b1), .RST_IN (rRST), /*AUTOINST*/ // Inputs .CLK (CLK)); // Start Flag Shift Register. Data enables are derived from the // taps on this shift register. shiftreg #(// Parameters .C_DEPTH (C_RX_PIPELINE_DEPTH), .C_WIDTH (1'b1), .C_VALUE (0) /*AUTOINSTPARAM*/) sop_shiftreg_inst (// Outputs .RD_DATA (wRxSrSop), // Inputs .WR_DATA (RX_TLP_START_FLAG & RX_TLP_VALID & (RX_SR_DATA[`TLP_TYPE_R] == `TLP_TYPE_CPL)), .RST_IN (0), /*AUTOINST*/ // Inputs .CLK (CLK)); endmodule
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * 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. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // 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 REGENTS OF THE // UNIVERSITY OF CALIFORNIA 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. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: rxc_engine_classic.v // Version: 1.0 // Verilog Standard: Verilog-2001 // Description: The RXC Engine (Classic) takes a single stream of TLP // packets and provides the completion packets on the RXC Interface. // This Engine is capable of operating at "line rate". // Author: Dustin Richmond (@darichmond) //----------------------------------------------------------------------------- `timescale 1ns/1ns `include "trellis.vh" `include "tlp.vh" module rxc_engine_classic #(parameter C_VENDOR = "ALTERA", parameter C_PCI_DATA_WIDTH = 128, parameter C_RX_PIPELINE_DEPTH = 10) (// Interface: Clocks input CLK, // Interface: Resets input RST_BUS, // Replacement for generic RST_IN input RST_LOGIC, // Addition for RIFFA_RST output DONE_RXC_RST, // Interface: RX Classic input [C_PCI_DATA_WIDTH-1:0] RX_TLP, input RX_TLP_VALID, input RX_TLP_START_FLAG, input [`SIG_OFFSET_W-1:0] RX_TLP_START_OFFSET, input RX_TLP_END_FLAG, input [`SIG_OFFSET_W-1:0] RX_TLP_END_OFFSET, input [`SIG_BARDECODE_W-1:0] RX_TLP_BAR_DECODE, // Interface: RXC Engine output [C_PCI_DATA_WIDTH-1:0] RXC_DATA, output RXC_DATA_VALID, output [(C_PCI_DATA_WIDTH/32)-1:0] RXC_DATA_WORD_ENABLE, output RXC_DATA_START_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] RXC_DATA_START_OFFSET, output RXC_DATA_END_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] RXC_DATA_END_OFFSET, output [`SIG_LBE_W-1:0] RXC_META_LDWBE, output [`SIG_FBE_W-1:0] RXC_META_FDWBE, output [`SIG_TAG_W-1:0] RXC_META_TAG, output [`SIG_LOWADDR_W-1:0] RXC_META_ADDR, output [`SIG_TYPE_W-1:0] RXC_META_TYPE, output [`SIG_LEN_W-1:0] RXC_META_LENGTH, output [`SIG_BYTECNT_W-1:0] RXC_META_BYTES_REMAINING, output [`SIG_CPLID_W-1:0] RXC_META_COMPLETER_ID, output RXC_META_EP, // Interface: RX Shift Register input [(C_RX_PIPELINE_DEPTH+1)*C_PCI_DATA_WIDTH-1:0] RX_SR_DATA, input [C_RX_PIPELINE_DEPTH:0] RX_SR_EOP, input [(C_RX_PIPELINE_DEPTH+1)*`SIG_OFFSET_W-1:0] RX_SR_END_OFFSET, input [C_RX_PIPELINE_DEPTH:0] RX_SR_SOP, input [C_RX_PIPELINE_DEPTH:0] RX_SR_VALID); /*AUTOWIRE*/ /*AUTOINPUT*/ ///*AUTOOUTPUT*/ // End of automatics localparam C_RX_BE_W = (`SIG_FBE_W+`SIG_LBE_W); localparam C_RX_INPUT_STAGES = 1; localparam C_RX_OUTPUT_STAGES = 1; // Must always be at least one localparam C_RX_COMPUTATION_STAGES = 1; localparam C_RX_DATA_STAGES = C_RX_COMPUTATION_STAGES; localparam C_RX_META_STAGES = C_RX_DATA_STAGES - 1; localparam C_TOTAL_STAGES = C_RX_COMPUTATION_STAGES + C_RX_OUTPUT_STAGES + C_RX_INPUT_STAGES; // Cycle index in the SOP register when enable is raised // Computation can begin when the last DW of the header is recieved. localparam C_RX_COMPUTATION_CYCLE = C_RX_COMPUTATION_STAGES + (`TLP_CPLMETADW2_I/C_PCI_DATA_WIDTH); // The computation cycle must be at least one cycle before the address is enabled localparam C_RX_DATA_CYCLE = C_RX_COMPUTATION_CYCLE; localparam C_RX_METADW0_CYCLE = (`TLP_CPLMETADW0_I/C_PCI_DATA_WIDTH) + C_RX_INPUT_STAGES; localparam C_RX_METADW1_CYCLE = (`TLP_CPLMETADW1_I/C_PCI_DATA_WIDTH) + C_RX_INPUT_STAGES; localparam C_RX_METADW2_CYCLE = (`TLP_CPLMETADW2_I/C_PCI_DATA_WIDTH) + C_RX_INPUT_STAGES; localparam C_RX_METADW0_INDEX = C_PCI_DATA_WIDTH*C_RX_INPUT_STAGES + (`TLP_CPLMETADW0_I%C_PCI_DATA_WIDTH); localparam C_RX_METADW1_INDEX = C_PCI_DATA_WIDTH*C_RX_INPUT_STAGES + (`TLP_CPLMETADW1_I%C_PCI_DATA_WIDTH); localparam C_RX_METADW2_INDEX = C_PCI_DATA_WIDTH*C_RX_INPUT_STAGES + (`TLP_CPLMETADW2_I%C_PCI_DATA_WIDTH); localparam C_OFFSET_WIDTH = clog2s(C_PCI_DATA_WIDTH/32); localparam C_MAX_ABLANK_WIDTH = 32; localparam C_MAX_START_OFFSET = (`TLP_MAXHDR_W + C_MAX_ABLANK_WIDTH)/32; localparam C_STD_START_DELAY = (64/C_PCI_DATA_WIDTH); wire [`TLP_CPLADDR_W-1:0] wAddr; wire [`TLP_CPLHDR_W-1:0] wMetadata; wire [`TLP_TYPE_W-1:0] wType; wire [`TLP_LEN_W-1:0] wLength; wire [2:0] wHdrLength; wire [2:0] wHdrLengthM1; wire [(C_PCI_DATA_WIDTH/32)-1:0] wEndMask; wire wEndFlag; wire [clog2s(C_PCI_DATA_WIDTH/32)-1:0] wEndOffset; wire [(C_PCI_DATA_WIDTH/32)-1:0] wStartMask; wire wStartFlag; wire _wStartFlag; wire [2:0] wStartOffset; wire [3:0] wStartFlags; wire wInsertBlank; wire [C_PCI_DATA_WIDTH-1:0] wRxcData; wire [95:0] wRxcMetadata; wire wRxcDataValid; wire wRxcDataEndFlag; wire [clog2s(C_PCI_DATA_WIDTH/32)-1:0] wRxcDataEndOffset; wire wRxcDataStartFlag; wire [clog2s(C_PCI_DATA_WIDTH/32)-1:0] wRxcDataStartOffset; wire [(C_PCI_DATA_WIDTH/32)-1:0] wRxcDataWordEnable; wire [C_RX_PIPELINE_DEPTH:0] wRxSrSop; reg rValid,_rValid; reg rRST; assign DONE_RXC_RST = ~rRST; // Calculate the header length (start offset), and header length minus 1 (end offset) assign wHdrLength = 3'b011; assign wHdrLengthM1 = 3'b010; // Determine if the TLP has an inserted blank before the payload assign wInsertBlank = ~wAddr[2] & (C_VENDOR == "ALTERA"); assign wStartOffset = (wHdrLength + {2'd0,wInsertBlank}); // Start offset in dwords assign wEndOffset = wHdrLengthM1 + wInsertBlank + wLength; //RX_SR_END_OFFSET[(C_TOTAL_STAGES-1)*`SIG_OFFSET_W +: C_OFFSET_WIDTH]; // Outputs assign RXC_DATA = RX_SR_DATA[(C_TOTAL_STAGES)*C_PCI_DATA_WIDTH +: C_PCI_DATA_WIDTH]; assign RXC_DATA_VALID = wRxcDataValid; assign RXC_DATA_END_FLAG = wRxcDataEndFlag; assign RXC_DATA_END_OFFSET = wRxcDataEndOffset; assign RXC_DATA_START_FLAG = wRxcDataStartFlag; assign RXC_DATA_START_OFFSET = wRxcDataStartOffset; assign RXC_META_LENGTH = wRxcMetadata[`TLP_LEN_R]; //assign RXC_META_TC = wRxcMetadata[`TLP_TC_R]; //assign RXC_META_ATTR = {wRxcMetadata[`TLP_ATTR1_R], wRxcMetadata[`TLP_ATTR0_R]}; assign RXC_META_TYPE = tlp_to_trellis_type({wRxcMetadata[`TLP_FMT_R],wRxcMetadata[`TLP_TYPE_R]}); assign RXC_META_ADDR = wRxcMetadata[`TLP_CPLADDR_R]; assign RXC_META_COMPLETER_ID = wRxcMetadata[`TLP_CPLCPLID_R]; assign RXC_META_BYTES_REMAINING = wRxcMetadata[`TLP_CPLBYTECNT_R]; assign RXC_META_TAG = wRxcMetadata[`TLP_CPLTAG_R]; assign RXC_META_EP = wRxcMetadata[`TLP_EP_R]; assign RXC_META_FDWBE = 0;// TODO: Remove (use addr) assign RXC_META_LDWBE = 0;// TODO: Remove (use addr) assign wEndFlag = RX_SR_EOP[C_RX_INPUT_STAGES+1]; assign _wStartFlag = wStartFlags != 0; generate if(C_PCI_DATA_WIDTH == 32) begin assign wStartFlags[3] = 0; assign wStartFlags[2] = wRxSrSop[C_RX_INPUT_STAGES + 3] & wMetadata[`TLP_PAYBIT_I] & ~rValid; // Any remaining cases assign wStartFlags[1] = wRxSrSop[C_RX_INPUT_STAGES + 2] & wMetadata[`TLP_PAYBIT_I] & ~wMetadata[`TLP_4DWHBIT_I]; // 3DWH, No Blank assign wStartFlags[0] = wRxSrSop[C_RX_INPUT_STAGES + 2] & ~wMetadata[`TLP_PAYBIT_I]; // No Payload end else if(C_PCI_DATA_WIDTH == 64) begin assign wStartFlags[3] = 0; assign wStartFlags[2] = wRxSrSop[C_RX_INPUT_STAGES + 2] & wMetadata[`TLP_PAYBIT_I] & ~rValid; // Any remaining cases if(C_VENDOR == "ALTERA") begin assign wStartFlags[1] = wRxSrSop[C_RX_INPUT_STAGES + 1] & wMetadata[`TLP_PAYBIT_I] & ~wMetadata[`TLP_4DWHBIT_I] & RX_SR_DATA[C_RX_METADW2_INDEX + 2]; // 3DWH, No Blank end else begin assign wStartFlags[1] = wRxSrSop[C_RX_INPUT_STAGES + 1] & wMetadata[`TLP_PAYBIT_I] & ~wMetadata[`TLP_4DWHBIT_I]; // 3DWH, No Blank end assign wStartFlags[0] = wRxSrSop[C_RX_INPUT_STAGES + 1] & ~wMetadata[`TLP_PAYBIT_I] & rValid; // No Payload end else if (C_PCI_DATA_WIDTH == 128) begin assign wStartFlags[3] = 0; assign wStartFlags[2] = wRxSrSop[C_RX_INPUT_STAGES + 1] & wMetadata[`TLP_PAYBIT_I] & ~rValid; // Is this correct? if(C_VENDOR == "ALTERA") begin assign wStartFlags[1] = wRxSrSop[C_RX_INPUT_STAGES] & RX_SR_DATA[C_RX_METADW0_INDEX + `TLP_PAYBIT_I] & ~RX_SR_DATA[C_RX_METADW0_INDEX + `TLP_4DWHBIT_I] & RX_SR_DATA[C_RX_METADW2_INDEX + 2]; // 3DWH, No Blank end else begin assign wStartFlags[1] = wRxSrSop[C_RX_INPUT_STAGES] & RX_SR_DATA[C_RX_METADW0_INDEX + `TLP_PAYBIT_I] & ~RX_SR_DATA[C_RX_METADW0_INDEX + `TLP_4DWHBIT_I]; end assign wStartFlags[0] = wRxSrSop[C_RX_INPUT_STAGES] & ~RX_SR_DATA[C_RX_METADW0_INDEX + `TLP_PAYBIT_I]; // No Payload end else begin // 256 assign wStartFlags[3] = 0; assign wStartFlags[2] = 0; assign wStartFlags[1] = 0; assign wStartFlags[0] = wRxSrSop[C_RX_INPUT_STAGES]; end // else: !if(C_PCI_DATA_WIDTH == 128) endgenerate always @(*) begin _rValid = rValid; if(_wStartFlag) begin _rValid = 1'b1; end else if (RX_SR_EOP[C_RX_INPUT_STAGES+1]) begin _rValid = 1'b0; end end always @(posedge CLK) begin if(rRST) begin rValid <= 1'b0; end else begin rValid <= _rValid; end end always @(posedge CLK) begin rRST <= RST_BUS | RST_LOGIC; end register #(// Parameters .C_WIDTH (32)) metadata_DW0_register (// Outputs .RD_DATA (wMetadata[31:0]), // Inputs .RST_IN (0), .WR_DATA (RX_SR_DATA[C_RX_METADW0_INDEX +: 32]), .WR_EN (wRxSrSop[C_RX_METADW0_CYCLE]), /*AUTOINST*/ // Inputs .CLK (CLK)); register #(// Parameters .C_WIDTH (32)) meta_DW1_register (// Outputs .RD_DATA (wMetadata[63:32]), // Inputs .RST_IN (0), .WR_DATA (RX_SR_DATA[C_RX_METADW1_INDEX +: 32]), .WR_EN (wRxSrSop[C_RX_METADW1_CYCLE]), /*AUTOINST*/ // Inputs .CLK (CLK)); register #(// Parameters .C_WIDTH (32)) meta_DW2_register (// Outputs .RD_DATA (wMetadata[95:64]), // Inputs .RST_IN (0), .WR_DATA (RX_SR_DATA[C_RX_METADW2_INDEX +: 32]), .WR_EN (wRxSrSop[C_RX_METADW2_CYCLE]), /*AUTOINST*/ // Inputs .CLK (CLK)); register #(// Parameters .C_WIDTH (`TLP_TYPE_W)) metadata_type_register (// Outputs .RD_DATA (wType), // Inputs .RST_IN (0), .WR_DATA (RX_SR_DATA[(`TLP_TYPE_I + C_PCI_DATA_WIDTH*C_RX_INPUT_STAGES) +: `TLP_TYPE_W]), .WR_EN (wRxSrSop[`TLP_TYPE_I/C_PCI_DATA_WIDTH + C_RX_INPUT_STAGES]), /*AUTOINST*/ // Inputs .CLK (CLK)); register #(// Parameters .C_WIDTH (`TLP_LEN_W)) metadata_length_register (// Outputs .RD_DATA (wLength), // Inputs .RST_IN (0), .WR_DATA (RX_SR_DATA[((`TLP_LEN_I%C_PCI_DATA_WIDTH) + C_PCI_DATA_WIDTH*C_RX_INPUT_STAGES) +: `TLP_LEN_W]), .WR_EN (wRxSrSop[`TLP_LEN_I/C_PCI_DATA_WIDTH + C_RX_INPUT_STAGES]), /*AUTOINST*/ // Inputs .CLK (CLK)); register #(// Parameters .C_WIDTH (`TLP_CPLADDR_W)) metadata_address_register (// Outputs .RD_DATA (wAddr), // Inputs .RST_IN (0), .WR_DATA (RX_SR_DATA[((`TLP_CPLADDR_I%C_PCI_DATA_WIDTH) + C_PCI_DATA_WIDTH*C_RX_INPUT_STAGES) +: `TLP_CPLADDR_W]), .WR_EN (wRxSrSop[`TLP_CPLADDR_I/C_PCI_DATA_WIDTH + C_RX_INPUT_STAGES]), /*AUTOINST*/ // Inputs .CLK (CLK)); register #(// Parameters .C_WIDTH (1), .C_VALUE (1'b0) /*AUTOINSTPARAM*/) start_flag_register (// Outputs .RD_DATA (wStartFlag), // Inputs .RST_IN (0), .WR_DATA (_wStartFlag), .WR_EN (1), /*AUTOINST*/ // Inputs .CLK (CLK)); assign wStartMask = {C_PCI_DATA_WIDTH/32{1'b1}} << ({C_OFFSET_WIDTH{wStartFlag}}& wStartOffset[C_OFFSET_WIDTH-1:0]); offset_to_mask #(// Parameters .C_MASK_SWAP (0), .C_MASK_WIDTH (C_PCI_DATA_WIDTH/32) /*AUTOINSTPARAM*/) o2m_ef (// Outputs .MASK (wEndMask), // Inputs .OFFSET_ENABLE (wEndFlag), .OFFSET (wEndOffset) /*AUTOINST*/); generate if(C_RX_OUTPUT_STAGES == 0) begin assign RXC_DATA_WORD_ENABLE = {wEndMask & wStartMask} & {C_PCI_DATA_WIDTH/32{~rValid | ~wMetadata[`TLP_PAYBIT_I]}}; end else begin register #(// Parameters .C_WIDTH (C_PCI_DATA_WIDTH/32), .C_VALUE (0) /*AUTOINSTPARAM*/) dw_enable (// Outputs .RD_DATA (wRxcDataWordEnable), // Inputs .RST_IN (~rValid | ~wMetadata[`TLP_PAYBIT_I]), .WR_DATA (wEndMask & wStartMask), .WR_EN (1), /*AUTOINST*/ // Inputs .CLK (CLK)); pipeline #(// Parameters .C_DEPTH (C_RX_OUTPUT_STAGES-1), .C_WIDTH (C_PCI_DATA_WIDTH/32), .C_USE_MEMORY (0) /*AUTOINSTPARAM*/) dw_pipeline (// Outputs .WR_DATA_READY (), // Pinned to 1 .RD_DATA (RXC_DATA_WORD_ENABLE), .RD_DATA_VALID (), // Inputs .WR_DATA (wRxcDataWordEnable), .WR_DATA_VALID (1), .RD_DATA_READY (1'b1), .RST_IN (rRST), /*AUTOINST*/ // Inputs .CLK (CLK)); end endgenerate pipeline #(// Parameters .C_DEPTH (C_RX_OUTPUT_STAGES), .C_WIDTH (`TLP_CPLHDR_W + 2*(clog2s(C_PCI_DATA_WIDTH/32) + 1)), .C_USE_MEMORY (0) /*AUTOINSTPARAM*/) output_pipeline (// Outputs .WR_DATA_READY (), // Pinned to 1 .RD_DATA ({wRxcMetadata,wRxcDataStartFlag,wRxcDataStartOffset,wRxcDataEndFlag,wRxcDataEndOffset}), .RD_DATA_VALID (wRxcDataValid), // Inputs .WR_DATA ({wMetadata, wStartFlag,wStartOffset[C_OFFSET_WIDTH-1:0],wEndFlag,wEndOffset[C_OFFSET_WIDTH-1:0]}), .WR_DATA_VALID (rValid & RX_SR_VALID[C_TOTAL_STAGES - C_RX_OUTPUT_STAGES]), .RD_DATA_READY (1'b1), .RST_IN (rRST), /*AUTOINST*/ // Inputs .CLK (CLK)); // Start Flag Shift Register. Data enables are derived from the // taps on this shift register. shiftreg #(// Parameters .C_DEPTH (C_RX_PIPELINE_DEPTH), .C_WIDTH (1'b1), .C_VALUE (0) /*AUTOINSTPARAM*/) sop_shiftreg_inst (// Outputs .RD_DATA (wRxSrSop), // Inputs .WR_DATA (RX_TLP_START_FLAG & RX_TLP_VALID & (RX_SR_DATA[`TLP_TYPE_R] == `TLP_TYPE_CPL)), .RST_IN (0), /*AUTOINST*/ // Inputs .CLK (CLK)); endmodule
`timescale 1ns/1ps module tb_multiplier (); /* this is automatically generated */ reg clk; // clock initial begin clk = 0; forever #5 clk = ~clk; end `ifdef SINGLE parameter SW = 24; `endif `ifdef DOUBLE parameter SW = 54;// */ `endif // (*NOTE*) replace reset, clock reg [SW-1:0] a; reg [SW-1:0] b; // wire [2*SW-2:0] BinaryRES; wire [2*SW-1:0] FKOARES; reg clk; reg rst; reg load_b_i; `ifdef SINGLE Sgf_Multiplication_SW24 #(.SW(SW)) `endif `ifdef DOUBLE Sgf_Multiplication_SW54 #(.SW(SW)) `endif inst_Sgf_Multiplication (.clk(clk),.rst(rst),.load_b_i(load_b_i),.Data_A_i(a), .Data_B_i(b), .sgf_result_o(FKOARES)); integer i = 1; parameter cycles = 1024; initial begin $monitor(a,b, FKOARES, a*b); end initial begin b = 1; rst = 1; a = 1; load_b_i = 0; #30; rst = 0; #15; load_b_i = 1; #100; b = 2; repeat (cycles) begin a = i; b = b + 2; i = i + 1; #50; end $finish; end endmodule
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * 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. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // 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 REGENTS OF THE // UNIVERSITY OF CALIFORNIA 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. // ---------------------------------------------------------------------- ////////////////////////////////////////////////////////////////////////////////// // Company: // Engineer: // // Create Date: 19:27:32 06/14/2012 // Design Name: // Module Name: reorder_queue // Project Name: // Target Devices: // Tool versions: // Description: // Reorders downstream TLPs to output in increasing tag sequence. Input packets // are stored in RAM and then read out when all previous sequence numbers have // arrived and been read out. This module also provides the next available tag // for the TX engine to use when sending memory request TLPs. // // Dependencies: // reorder_queue_input.v // reorder_queue_output.v // // Revision: // Revision 0.01 - File Created // Additional Comments: // ////////////////////////////////////////////////////////////////////////////////// `include "trellis.vh" `timescale 1ns / 1ps module reorder_queue #( parameter C_PCI_DATA_WIDTH = 9'd128, parameter C_NUM_CHNL = 4'd12, parameter C_MAX_READ_REQ_BYTES = 512, // Max size of read requests (in bytes) parameter C_TAG_WIDTH = 5, // Number of outstanding requests // Local parameters parameter C_PCI_DATA_WORD = C_PCI_DATA_WIDTH/32, parameter C_PCI_DATA_COUNT_WIDTH = clog2(C_PCI_DATA_WORD+1), parameter C_NUM_TAGS = 2**C_TAG_WIDTH, parameter C_DW_PER_TAG = C_MAX_READ_REQ_BYTES/4, parameter C_TAG_DW_COUNT_WIDTH = clog2s(C_DW_PER_TAG+1), parameter C_DATA_ADDR_STRIDE_WIDTH = clog2s(C_DW_PER_TAG/C_PCI_DATA_WORD), // div by C_PCI_DATA_WORD b/c there are C_PCI_DATA_WORD RAMs parameter C_DATA_ADDR_WIDTH = C_TAG_WIDTH + C_DATA_ADDR_STRIDE_WIDTH ) ( input CLK, // Clock input RST, // Synchronous reset input VALID, // Valid input packet input [C_PCI_DATA_WIDTH-1:0] DATA, // Input packet payload input [(C_PCI_DATA_WIDTH/32)-1:0] DATA_EN, // Input packet payload data enable input DATA_START_FLAG, // Input packet payload input [clog2s(C_PCI_DATA_WIDTH/32)-1:0] DATA_START_OFFSET, // Input packet payload data enable count input DATA_END_FLAG, // Input packet payload input [clog2s(C_PCI_DATA_WIDTH/32)-1:0] DATA_END_OFFSET, // Input packet payload data enable count input DONE, // Input packet done input ERR, // Input packet has error input [C_TAG_WIDTH-1:0] TAG, // Input packet tag (external tag) input [5:0] INT_TAG, // Internal tag to exchange with external input INT_TAG_VALID, // High to signal tag exchange output [C_TAG_WIDTH-1:0] EXT_TAG, // External tag to provide in exchange for internal tag output EXT_TAG_VALID, // High to signal external tag is valid output [C_PCI_DATA_WIDTH-1:0] ENG_DATA, // Engine data output [(C_NUM_CHNL*C_PCI_DATA_COUNT_WIDTH)-1:0] MAIN_DATA_EN, // Main data enable output [C_NUM_CHNL-1:0] MAIN_DONE, // Main data complete output [C_NUM_CHNL-1:0] MAIN_ERR, // Main data completed with error output [(C_NUM_CHNL*C_PCI_DATA_COUNT_WIDTH)-1:0] SG_RX_DATA_EN, // Scatter gather for RX data enable output [C_NUM_CHNL-1:0] SG_RX_DONE, // Scatter gather for RX data complete output [C_NUM_CHNL-1:0] SG_RX_ERR, // Scatter gather for RX data completed with error output [(C_NUM_CHNL*C_PCI_DATA_COUNT_WIDTH)-1:0] SG_TX_DATA_EN, // Scatter gather for TX data enable output [C_NUM_CHNL-1:0] SG_TX_DONE, // Scatter gather for TX data complete output [C_NUM_CHNL-1:0] SG_TX_ERR // Scatter gather for TX data completed with error ); wire [(C_DATA_ADDR_WIDTH*C_PCI_DATA_WORD)-1:0] wWrDataAddr; wire [C_PCI_DATA_WIDTH-1:0] wWrData; wire [C_PCI_DATA_WORD-1:0] wWrDataEn; wire [C_TAG_WIDTH-1:0] wWrPktTag; wire [C_TAG_DW_COUNT_WIDTH-1:0] wWrPktWords; wire wWrPktWordsLTE1; wire wWrPktWordsLTE2; wire wWrPktValid; wire wWrPktDone; wire wWrPktErr; wire [C_DATA_ADDR_WIDTH-1:0] wRdDataAddr; wire [C_PCI_DATA_WIDTH-1:0] wRdData; wire [C_TAG_WIDTH-1:0] wRdPktTag; wire [(1+1+1+1+C_TAG_DW_COUNT_WIDTH)-1:0] wRdPktInfo; wire [5:0] wRdTagMap; wire [C_NUM_TAGS-1:0] wFinish; wire [C_NUM_TAGS-1:0] wClear; reg [C_TAG_WIDTH-1:0] rPos=0; reg rValid=0; reg [C_NUM_TAGS-1:0] rFinished=0; reg [C_NUM_TAGS-1:0] rUse=0; reg [C_NUM_TAGS-1:0] rUsing=0; assign EXT_TAG = rPos; assign EXT_TAG_VALID = rValid; // Move through tag/slot/bucket space. always @ (posedge CLK) begin if (RST) begin rPos <= #1 0; rUse <= #1 0; rValid <= #1 0; end else begin if (INT_TAG_VALID & EXT_TAG_VALID) begin rPos <= #1 rPos + 1'd1; rUse <= #1 1<<rPos; rValid <= #1 !rUsing[rPos + 1'd1]; end else begin rUse <= #1 0; rValid <= #1 !rUsing[rPos]; end end end // Update tag/slot/bucket status. always @ (posedge CLK) begin if (RST) begin rUsing <= #1 0; rFinished <= #1 0; end else begin rUsing <= #1 (rUsing | rUse) & ~wClear; rFinished <= #1 (rFinished | wFinish) & ~wClear; end end genvar r; generate for (r = 0; r < C_PCI_DATA_WORD; r = r + 1) begin : rams // RAMs for packet reordering. (* RAM_STYLE="BLOCK" *) ram_1clk_1w_1r #(.C_RAM_WIDTH(32), .C_RAM_DEPTH(C_NUM_TAGS*C_DW_PER_TAG/C_PCI_DATA_WORD) ) ram ( .CLK(CLK), .ADDRA(wWrDataAddr[C_DATA_ADDR_WIDTH*r +:C_DATA_ADDR_WIDTH]), .WEA(wWrDataEn[r]), .DINA(wWrData[32*r +:32]), .ADDRB(wRdDataAddr), .DOUTB(wRdData[32*r +:32]) ); end endgenerate // RAM for bucket done, err, final DW count (* RAM_STYLE="DISTRIBUTED" *) ram_1clk_1w_1r #(.C_RAM_WIDTH(1 + 1 + 1 + 1 + C_TAG_DW_COUNT_WIDTH), .C_RAM_DEPTH(C_NUM_TAGS)) pktRam ( .CLK(CLK), .ADDRA(wWrPktTag), .WEA((wWrPktDone | wWrPktErr) & wWrPktValid), .DINA({wWrPktDone, wWrPktErr, wWrPktWordsLTE2, wWrPktWordsLTE1, wWrPktWords}), .ADDRB(wRdPktTag), .DOUTB(wRdPktInfo) ); // RAM for tag map (* RAM_STYLE="DISTRIBUTED" *) ram_1clk_1w_1r #(.C_RAM_WIDTH(6), .C_RAM_DEPTH(C_NUM_TAGS)) mapRam ( .CLK(CLK), .ADDRA(rPos), .WEA(INT_TAG_VALID & EXT_TAG_VALID), .DINA(INT_TAG), .ADDRB(wRdPktTag), .DOUTB(wRdTagMap) ); // Demux input data into the correct slot/bucket. reorder_queue_input #( .C_PCI_DATA_WIDTH(C_PCI_DATA_WIDTH), .C_TAG_WIDTH(C_TAG_WIDTH), .C_TAG_DW_COUNT_WIDTH(C_TAG_DW_COUNT_WIDTH), .C_DATA_ADDR_STRIDE_WIDTH(C_DATA_ADDR_STRIDE_WIDTH), .C_DATA_ADDR_WIDTH(C_DATA_ADDR_WIDTH) ) data_input ( .CLK(CLK), .RST(RST), .VALID(VALID), .DATA_START_FLAG (DATA_START_FLAG), .DATA_START_OFFSET (DATA_START_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .DATA_END_FLAG (DATA_END_FLAG), .DATA_END_OFFSET (DATA_END_OFFSET[clog2s(C_PCI_DATA_WIDTH/32)-1:0]), .DATA (DATA), .DATA_EN (DATA_EN), .DONE(DONE), .ERR(ERR), .TAG(TAG), .TAG_FINISH(wFinish), .TAG_CLEAR(wClear), .STORED_DATA_ADDR(wWrDataAddr), .STORED_DATA(wWrData), .STORED_DATA_EN(wWrDataEn), .PKT_VALID(wWrPktValid), .PKT_TAG(wWrPktTag), .PKT_WORDS(wWrPktWords), .PKT_WORDS_LTE1(wWrPktWordsLTE1), .PKT_WORDS_LTE2(wWrPktWordsLTE2), .PKT_DONE(wWrPktDone), .PKT_ERR(wWrPktErr) ); // Output packets in increasing tag order. reorder_queue_output #( .C_PCI_DATA_WIDTH(C_PCI_DATA_WIDTH), .C_NUM_CHNL(C_NUM_CHNL), .C_TAG_WIDTH(C_TAG_WIDTH), .C_TAG_DW_COUNT_WIDTH(C_TAG_DW_COUNT_WIDTH), .C_DATA_ADDR_STRIDE_WIDTH(C_DATA_ADDR_STRIDE_WIDTH), .C_DATA_ADDR_WIDTH(C_DATA_ADDR_WIDTH) ) data_output ( .CLK(CLK), .RST(RST), .DATA_ADDR(wRdDataAddr), .DATA(wRdData), .TAG_FINISHED(rFinished), .TAG_CLEAR(wClear), .TAG(wRdPktTag), .TAG_MAPPED(wRdTagMap), .PKT_WORDS(wRdPktInfo[0 +:C_TAG_DW_COUNT_WIDTH]), .PKT_WORDS_LTE1(wRdPktInfo[C_TAG_DW_COUNT_WIDTH]), .PKT_WORDS_LTE2(wRdPktInfo[C_TAG_DW_COUNT_WIDTH+1]), .PKT_ERR(wRdPktInfo[C_TAG_DW_COUNT_WIDTH+2]), .PKT_DONE(wRdPktInfo[C_TAG_DW_COUNT_WIDTH+3]), .ENG_DATA(ENG_DATA), .MAIN_DATA_EN(MAIN_DATA_EN), .MAIN_DONE(MAIN_DONE), .MAIN_ERR(MAIN_ERR), .SG_RX_DATA_EN(SG_RX_DATA_EN), .SG_RX_DONE(SG_RX_DONE), .SG_RX_ERR(SG_RX_ERR), .SG_TX_DATA_EN(SG_TX_DATA_EN), .SG_TX_DONE(SG_TX_DONE), .SG_TX_ERR(SG_TX_ERR) ); endmodule
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * 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. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // 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 REGENTS OF THE // UNIVERSITY OF CALIFORNIA 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. // ---------------------------------------------------------------------- `include "functions.vh" module offset_to_mask #(parameter C_MASK_SWAP = 1, parameter C_MASK_WIDTH = 4) ( input OFFSET_ENABLE, input [clog2s(C_MASK_WIDTH)-1:0] OFFSET, output [C_MASK_WIDTH-1:0] MASK ); reg [7:0] _rMask,_rMaskSwap; wire [3:0] wSelect; assign wSelect = {OFFSET_ENABLE,{{(3-clog2s(C_MASK_WIDTH)){1'b0}},OFFSET}}; assign MASK = (C_MASK_SWAP)? _rMaskSwap[7 -: C_MASK_WIDTH]: _rMask[C_MASK_WIDTH-1:0]; always @(*) begin _rMask = 0; _rMaskSwap = 0; /* verilator lint_off CASEX */ casex(wSelect) default: begin _rMask = 8'b1111_1111; _rMaskSwap = 8'b1111_1111; end 4'b1000: begin _rMask = 8'b0000_0001; _rMaskSwap = 8'b1111_1111; end 4'b1001: begin _rMask = 8'b0000_0011; _rMaskSwap = 8'b0111_1111; end 4'b1010: begin _rMask = 8'b0000_0111; _rMaskSwap = 8'b0011_1111; end 4'b1011: begin _rMask = 8'b0000_1111; _rMaskSwap = 8'b0001_1111; end 4'b1100: begin _rMask = 8'b0001_1111; _rMaskSwap = 8'b0000_1111; end 4'b1101: begin _rMask = 8'b0011_1111; _rMaskSwap = 8'b0000_0111; end 4'b1110: begin _rMask = 8'b0111_1111; _rMaskSwap = 8'b0000_0011; end 4'b1111: begin _rMask = 8'b1111_1111; _rMaskSwap = 8'b0000_0001; end endcase // casez ({OFFSET_MASK,OFFSET}) /* verilator lint_on CASEX */ end endmodule
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * 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. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // 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 REGENTS OF THE // UNIVERSITY OF CALIFORNIA 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. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: tx_port_monitor_64.v // Version: 1.00.a // Verilog Standard: Verilog-2001 // Description: Detects transaction open/close events from the stream // of data from the tx_port_channel_gate. Filters out events and passes data // onto the tx_port_buffer. // Author: Matt Jacobsen // History: @mattj: Version 2.0 //----------------------------------------------------------------------------- `define S_TXPORTMON64_NEXT 6'b00_0001 `define S_TXPORTMON64_EVT_2 6'b00_0010 `define S_TXPORTMON64_TXN 6'b00_0100 `define S_TXPORTMON64_READ 6'b00_1000 `define S_TXPORTMON64_END_0 6'b01_0000 `define S_TXPORTMON64_END_1 6'b10_0000 `timescale 1ns/1ns module tx_port_monitor_64 #( parameter C_DATA_WIDTH = 9'd64, parameter C_FIFO_DEPTH = 512, // Local parameters parameter C_FIFO_DEPTH_THRESH = (C_FIFO_DEPTH - 4), parameter C_FIFO_DEPTH_WIDTH = clog2((2**clog2(C_FIFO_DEPTH))+1), parameter C_VALID_HIST = 1 ) ( input RST, input CLK, input [C_DATA_WIDTH:0] EVT_DATA, // Event data from tx_port_channel_gate input EVT_DATA_EMPTY, // Event data FIFO is empty output EVT_DATA_RD_EN, // Event data FIFO read enable output [C_DATA_WIDTH-1:0] WR_DATA, // Output data output WR_EN, // Write enable for output data input [C_FIFO_DEPTH_WIDTH-1:0] WR_COUNT, // Output FIFO count output TXN, // Transaction parameters are valid input ACK, // Transaction parameter read, continue output LAST, // Channel last write output [31:0] LEN, // Channel write length (in 32 bit words) output [30:0] OFF, // Channel write offset output [31:0] WORDS_RECVD, // Count of data words received in transaction output DONE, // Transaction is closed input TX_ERR // Transaction encountered an error ); `include "functions.vh" (* syn_encoding = "user" *) (* fsm_encoding = "user" *) reg [5:0] rState=`S_TXPORTMON64_NEXT, _rState=`S_TXPORTMON64_NEXT; reg rRead=0, _rRead=0; reg [C_VALID_HIST-1:0] rDataValid={C_VALID_HIST{1'd0}}, _rDataValid={C_VALID_HIST{1'd0}}; reg rEvent=0, _rEvent=0; reg [63:0] rReadData=64'd0, _rReadData=64'd0; reg [31:0] rWordsRecvd=0, _rWordsRecvd=0; reg [31:0] rWordsRecvdAdv=0, _rWordsRecvdAdv=0; reg rAlmostAllRecvd=0, _rAlmostAllRecvd=0; reg rAlmostFull=0, _rAlmostFull=0; reg rLenEQ0Hi=0, _rLenEQ0Hi=0; reg rLenEQ0Lo=0, _rLenEQ0Lo=0; reg rLenLE2Lo=0, _rLenLE2Lo=0; reg rTxErr=0, _rTxErr=0; wire wEventData = (rDataValid[0] & EVT_DATA[C_DATA_WIDTH]); wire wPayloadData = (rDataValid[0] & !EVT_DATA[C_DATA_WIDTH] & rState[3]); // S_TXPORTMON64_READ wire wAllWordsRecvd = ((rAlmostAllRecvd | (rLenEQ0Hi & rLenLE2Lo)) & wPayloadData); assign EVT_DATA_RD_EN = rRead; assign WR_DATA = EVT_DATA[C_DATA_WIDTH-1:0]; assign WR_EN = wPayloadData; // S_TXPORTMON64_READ assign TXN = rState[2]; // S_TXPORTMON64_TXN assign LAST = rReadData[0]; assign OFF = rReadData[31:1]; assign LEN = rReadData[63:32]; assign WORDS_RECVD = rWordsRecvd; assign DONE = !rState[3]; // !S_TXPORTMON64_READ // Buffer the input signals that come from outside the tx_port. always @ (posedge CLK) begin rTxErr <= #1 (RST ? 1'd0 : _rTxErr); end always @ (*) begin _rTxErr = TX_ERR; end // Transaction monitoring FSM. always @ (posedge CLK) begin rState <= #1 (RST ? `S_TXPORTMON64_NEXT : _rState); end always @ (*) begin _rState = rState; case (rState) `S_TXPORTMON64_NEXT: begin // Read, wait for start of transaction event if (rEvent) _rState = `S_TXPORTMON64_EVT_2; end `S_TXPORTMON64_EVT_2: begin // Read, wait for start of transaction event if (rEvent) _rState = `S_TXPORTMON64_TXN; end `S_TXPORTMON64_TXN: begin // Don't read, wait until transaction has been acknowledged if (ACK) _rState = ((rLenEQ0Hi && rLenEQ0Lo) ? `S_TXPORTMON64_END_0 : `S_TXPORTMON64_READ); end `S_TXPORTMON64_READ: begin // Continue reading, wait for end of transaction event or all expected data if (rEvent) _rState = `S_TXPORTMON64_END_1; else if (wAllWordsRecvd | rTxErr) _rState = `S_TXPORTMON64_END_0; end `S_TXPORTMON64_END_0: begin // Continue reading, wait for first end of transaction event if (rEvent) _rState = `S_TXPORTMON64_END_1; end `S_TXPORTMON64_END_1: begin // Continue reading, wait for second end of transaction event if (rEvent) _rState = `S_TXPORTMON64_NEXT; end default: begin _rState = `S_TXPORTMON64_NEXT; end endcase end // Manage reading from the FIFO and tracking amounts read. always @ (posedge CLK) begin rRead <= #1 (RST ? 1'd0 : _rRead); rDataValid <= #1 (RST ? {C_VALID_HIST{1'd0}} : _rDataValid); rEvent <= #1 (RST ? 1'd0 : _rEvent); rReadData <= #1 _rReadData; rWordsRecvd <= #1 _rWordsRecvd; rWordsRecvdAdv <= #1 _rWordsRecvdAdv; rAlmostAllRecvd <= #1 _rAlmostAllRecvd; rAlmostFull <= #1 _rAlmostFull; rLenEQ0Hi <= #1 _rLenEQ0Hi; rLenEQ0Lo <= #1 _rLenEQ0Lo; rLenLE2Lo <= #1 _rLenLE2Lo; end always @ (*) begin // Don't get to the full point in the output FIFO _rAlmostFull = (WR_COUNT >= C_FIFO_DEPTH_THRESH); // Track read history so we know when data is valid _rDataValid = ((rDataValid<<1) | (rRead & !EVT_DATA_EMPTY)); // Read until we get a (valid) event _rRead = (!rState[2] & !(rState[1] & rEvent) & !wEventData & !rAlmostFull); // !S_TXPORTMON64_TXN // Track detected events _rEvent = wEventData; // Save event data when valid if (wEventData) _rReadData = EVT_DATA[C_DATA_WIDTH-1:0]; else _rReadData = rReadData; // If LEN == 0, we don't want to send any data to the output _rLenEQ0Hi = (LEN[31:16] == 16'd0); _rLenEQ0Lo = (LEN[15:0] == 16'd0); // If LEN <= 2, we want to trigger the almost all received flag _rLenLE2Lo = (LEN[15:0] <= 16'd2); // Count received non-event data _rWordsRecvd = (ACK ? 0 : rWordsRecvd + (wPayloadData<<1)); _rWordsRecvdAdv = (ACK ? 2*(C_DATA_WIDTH/32) : rWordsRecvdAdv + (wPayloadData<<1)); _rAlmostAllRecvd = ((rWordsRecvdAdv >= LEN) && wPayloadData); end /* wire [35:0] wControl0; chipscope_icon_1 cs_icon( .CONTROL0(wControl0) ); chipscope_ila_t8_512 a0( .CLK(CLK), .CONTROL(wControl0), .TRIG0({TXN, wPayloadData, wEventData, rState}), .DATA({297'd0, WR_COUNT, // 10 wPayloadData, // 1 EVT_DATA_RD_EN, // 1 RST, // 1 rTxErr, // 1 wEventData, // 1 rReadData, // 64 OFF, // 31 LEN, // 32 LAST, // 1 TXN, // 1 EVT_DATA_EMPTY, // 1 EVT_DATA, // 65 rState}) // 5 ); */ endmodule
//***************************************************************************** // (c) Copyright 2009 - 2013 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: iodelay_ctrl.v // /___/ /\ Date Last Modified: $Date: 2011/06/02 08:34:56 $ // \ \ / \ Date Created: Wed Aug 16 2006 // \___\/\___\ // //Device: Virtex-6 //Design Name: DDR3 SDRAM //Purpose: // This module instantiates the IDELAYCTRL primitive, which continously // calibrates the IODELAY elements in the region to account for varying // environmental conditions. A 200MHz or 300MHz reference clock (depending // on the desired IODELAY tap resolution) must be supplied //Reference: //Revision History: //***************************************************************************** /****************************************************************************** **$Id: iodelay_ctrl.v,v 1.1 2011/06/02 08:34:56 mishra Exp $ **$Date: 2011/06/02 08:34:56 $ **$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/clocking/iodelay_ctrl.v,v $ ******************************************************************************/ `timescale 1ps/1ps module mig_7series_v1_9_iodelay_ctrl # ( parameter TCQ = 100, // clk->out delay (sim only) parameter IODELAY_GRP = "IODELAY_MIG", // May be assigned unique name when // multiple IP cores used in design parameter REFCLK_TYPE = "DIFFERENTIAL", // Reference clock type // "DIFFERENTIAL","SINGLE_ENDED" // NO_BUFFER, USE_SYSTEM_CLOCK parameter SYSCLK_TYPE = "DIFFERENTIAL", // input clock type // DIFFERENTIAL, SINGLE_ENDED, // NO_BUFFER parameter SYS_RST_PORT = "FALSE", // "TRUE" - if pin is selected for sys_rst // and IBUF will be instantiated. // "FALSE" - if pin is not selected for sys_rst parameter RST_ACT_LOW = 1, // Reset input polarity // (0 = active high, 1 = active low) parameter DIFF_TERM_REFCLK = "TRUE" // Differential Termination ) ( input clk_ref_p, input clk_ref_n, input clk_ref_i, input sys_rst, output clk_ref, output sys_rst_o, output iodelay_ctrl_rdy ); // # of clock cycles to delay deassertion of reset. Needs to be a fairly // high number not so much for metastability protection, but to give time // for reset (i.e. stable clock cycles) to propagate through all state // machines and to all control signals (i.e. not all control signals have // resets, instead they rely on base state logic being reset, and the effect // of that reset propagating through the logic). Need this because we may not // be getting stable clock cycles while reset asserted (i.e. since reset // depends on DCM lock status) // COMMENTED, RC, 01/13/09 - causes pack error in MAP w/ larger # localparam RST_SYNC_NUM = 15; // localparam RST_SYNC_NUM = 25; wire clk_ref_bufg; wire clk_ref_ibufg; wire rst_ref; (* keep = "true", max_fanout = 10 *) reg [RST_SYNC_NUM-1:0] rst_ref_sync_r /* synthesis syn_maxfan = 10 */; wire rst_tmp_idelay; wire sys_rst_act_hi; //*************************************************************************** // If the pin is selected for sys_rst in GUI, IBUF will be instantiated. // If the pin is not selected in GUI, sys_rst signal is expected to be // driven internally. generate if (SYS_RST_PORT == "TRUE") IBUF u_sys_rst_ibuf ( .I (sys_rst), .O (sys_rst_o) ); else assign sys_rst_o = sys_rst; endgenerate // Possible inversion of system reset as appropriate assign sys_rst_act_hi = RST_ACT_LOW ? ~sys_rst_o: sys_rst_o; //*************************************************************************** // 1) Input buffer for IDELAYCTRL reference clock - handle either a // differential or single-ended input. Global clock buffer is used to // drive the rest of FPGA logic. // 2) For NO_BUFFER option, Reference clock will be driven from internal // clock i.e., clock is driven from fabric. Input buffers and Global // clock buffers will not be instaitaed. // 3) For USE_SYSTEM_CLOCK, input buffer output of system clock will be used // as the input reference clock. Global clock buffer is used to drive // the rest of FPGA logic. //*************************************************************************** generate if (REFCLK_TYPE == "DIFFERENTIAL") begin: diff_clk_ref IBUFGDS # ( .DIFF_TERM (DIFF_TERM_REFCLK), .IBUF_LOW_PWR ("FALSE") ) u_ibufg_clk_ref ( .I (clk_ref_p), .IB (clk_ref_n), .O (clk_ref_ibufg) ); BUFG u_bufg_clk_ref ( .O (clk_ref_bufg), .I (clk_ref_ibufg) ); end else if (REFCLK_TYPE == "SINGLE_ENDED") begin : se_clk_ref IBUFG # ( .IBUF_LOW_PWR ("FALSE") ) u_ibufg_clk_ref ( .I (clk_ref_i), .O (clk_ref_ibufg) ); BUFG u_bufg_clk_ref ( .O (clk_ref_bufg), .I (clk_ref_ibufg) ); end else if ((REFCLK_TYPE == "NO_BUFFER") || (REFCLK_TYPE == "USE_SYSTEM_CLOCK" && SYSCLK_TYPE == "NO_BUFFER")) begin : clk_ref_noibuf_nobuf assign clk_ref_bufg = clk_ref_i; end else if (REFCLK_TYPE == "USE_SYSTEM_CLOCK" && SYSCLK_TYPE != "NO_BUFFER") begin : clk_ref_noibuf BUFG u_bufg_clk_ref ( .O (clk_ref_bufg), .I (clk_ref_i) ); end endgenerate //*************************************************************************** // Global clock buffer for IDELAY reference clock //*************************************************************************** assign clk_ref = clk_ref_bufg; //***************************************************************** // IDELAYCTRL reset // This assumes an external clock signal driving the IDELAYCTRL // blocks. Otherwise, if a PLL drives IDELAYCTRL, then the PLL // lock signal will need to be incorporated in this. //***************************************************************** // Add PLL lock if PLL drives IDELAYCTRL in user design assign rst_tmp_idelay = sys_rst_act_hi; always @(posedge clk_ref_bufg or posedge rst_tmp_idelay) if (rst_tmp_idelay) rst_ref_sync_r <= #TCQ {RST_SYNC_NUM{1'b1}}; else rst_ref_sync_r <= #TCQ rst_ref_sync_r << 1; assign rst_ref = rst_ref_sync_r[RST_SYNC_NUM-1]; //***************************************************************** (* IODELAY_GROUP = IODELAY_GRP *) IDELAYCTRL u_idelayctrl ( .RDY (iodelay_ctrl_rdy), .REFCLK (clk_ref_bufg), .RST (rst_ref) ); endmodule
(** * Equiv: Program Equivalence *) Require Export Imp. (** *** Some general advice for working on exercises: - Most of the Coq proofs we ask you to do are similar to proofs that we've provided. Before starting to work on the homework problems, take the time to work through our proofs (both informally, on paper, and in Coq) and make sure you understand them in detail. This will save you a lot of time. - The Coq proofs we're doing now are sufficiently complicated that it is more or less impossible to complete them simply by random experimentation or "following your nose." You need to start with an idea about why the property is true and how the proof is going to go. The best way to do this is to write out at least a sketch of an informal proof on paper -- one that intuitively convinces you of the truth of the theorem -- before starting to work on the formal one. Alternately, grab a friend and try to convince them that the theorem is true; then try to formalize your explanation. - Use automation to save work! Some of the proofs in this chapter's exercises are pretty long if you try to write out all the cases explicitly. *) (* ####################################################### *) (** * Behavioral Equivalence *) (** In the last chapter, we investigated the correctness of a very simple program transformation: the [optimize_0plus] function. The programming language we were considering was the first version of the language of arithmetic expressions -- with no variables -- so in that setting it was very easy to define what it _means_ for a program transformation to be correct: it should always yield a program that evaluates to the same number as the original. To go further and talk about the correctness of program transformations in the full Imp language, we need to consider the role of variables and state. *) (* ####################################################### *) (** ** Definitions *) (** For [aexp]s and [bexp]s with variables, the definition we want is clear. We say that two [aexp]s or [bexp]s are _behaviorally equivalent_ if they evaluate to the same result _in every state_. *) Definition aequiv (a1 a2 : aexp) : Prop := forall (st:state), aeval st a1 = aeval st a2. Definition bequiv (b1 b2 : bexp) : Prop := forall (st:state), beval st b1 = beval st b2. (** For commands, the situation is a little more subtle. We can't simply say "two commands are behaviorally equivalent if they evaluate to the same ending state whenever they are started in the same initial state," because some commands (in some starting states) don't terminate in any final state at all! What we need instead is this: two commands are behaviorally equivalent if, for any given starting state, they either both diverge or both terminate in the same final state. A compact way to express this is "if the first one terminates in a particular state then so does the second, and vice versa." *) Definition cequiv (c1 c2 : com) : Prop := forall (st st' : state), (c1 / st || st') <-> (c2 / st || st'). (** **** Exercise: 2 stars (equiv_classes) *) (** Given the following programs, group together those that are equivalent in [Imp]. Your answer should be given as a list of lists, where each sub-list represents a group of equivalent programs. For example, if you think programs (a) through (h) are all equivalent to each other, but not to (i), your answer should look like this: [ [prog_a;prog_b;prog_c;prog_d;prog_e;prog_f;prog_g;prog_h] ; [prog_i] ] Write down your answer below in the definition of [equiv_classes]. *) Definition prog_a : com := WHILE BNot (BLe (AId X) (ANum 0)) DO X ::= APlus (AId X) (ANum 1) END. Definition prog_b : com := IFB BEq (AId X) (ANum 0) THEN X ::= APlus (AId X) (ANum 1);; Y ::= ANum 1 ELSE Y ::= ANum 0 FI;; X ::= AMinus (AId X) (AId Y);; Y ::= ANum 0. Definition prog_c : com := SKIP. Definition prog_d : com := WHILE BNot (BEq (AId X) (ANum 0)) DO X ::= APlus (AMult (AId X) (AId Y)) (ANum 1) END. Definition prog_e : com := Y ::= ANum 0. Definition prog_f : com := Y ::= APlus (AId X) (ANum 1);; WHILE BNot (BEq (AId X) (AId Y)) DO Y ::= APlus (AId X) (ANum 1) END. Definition prog_g : com := WHILE BTrue DO SKIP END. Definition prog_h : com := WHILE BNot (BEq (AId X) (AId X)) DO X ::= APlus (AId X) (ANum 1) END. Definition prog_i : com := WHILE BNot (BEq (AId X) (AId Y)) DO X ::= APlus (AId Y) (ANum 1) END. Definition equiv_classes : list (list com) := (* FILL IN HERE *) admit. (* GRADE_TEST 2: check_equiv_classes equiv_classes *) (** [] *) (* ####################################################### *) (** ** Examples *) (** Here are some simple examples of equivalences of arithmetic and boolean expressions. *) Theorem aequiv_example: aequiv (AMinus (AId X) (AId X)) (ANum 0). Proof. intros st. simpl. omega. Qed. Theorem bequiv_example: bequiv (BEq (AMinus (AId X) (AId X)) (ANum 0)) BTrue. Proof. intros st. unfold beval. rewrite aequiv_example. reflexivity. Qed. (** For examples of command equivalence, let's start by looking at some trivial program transformations involving [SKIP]: *) Theorem skip_left: forall c, cequiv (SKIP;; c) c. Proof. (* WORKED IN CLASS *) intros c st st'. split; intros H. Case "->". inversion H. subst. inversion H2. subst. assumption. Case "<-". apply E_Seq with st. apply E_Skip. assumption. Qed. (** **** Exercise: 2 stars (skip_right) *) (** Prove that adding a SKIP after a command results in an equivalent program *) Theorem skip_right: forall c, cequiv (c;; SKIP) c. Proof. (* FILL IN HERE *) Admitted. (** [] *) (** Similarly, here is a simple transformations that simplifies [IFB] commands: *) Theorem IFB_true_simple: forall c1 c2, cequiv (IFB BTrue THEN c1 ELSE c2 FI) c1. Proof. intros c1 c2. split; intros H. Case "->". inversion H; subst. assumption. inversion H5. Case "<-". apply E_IfTrue. reflexivity. assumption. Qed. (** Of course, few programmers would be tempted to write a conditional whose guard is literally [BTrue]. A more interesting case is when the guard is _equivalent_ to true: _Theorem_: If [b] is equivalent to [BTrue], then [IFB b THEN c1 ELSE c2 FI] is equivalent to [c1]. *) (** *** *) (** _Proof_: - ([->]) We must show, for all [st] and [st'], that if [IFB b THEN c1 ELSE c2 FI / st || st'] then [c1 / st || st']. Proceed by cases on the rules that could possibly have been used to show [IFB b THEN c1 ELSE c2 FI / st || st'], namely [E_IfTrue] and [E_IfFalse]. - Suppose the final rule rule in the derivation of [IFB b THEN c1 ELSE c2 FI / st || st'] was [E_IfTrue]. We then have, by the premises of [E_IfTrue], that [c1 / st || st']. This is exactly what we set out to prove. - On the other hand, suppose the final rule in the derivation of [IFB b THEN c1 ELSE c2 FI / st || st'] was [E_IfFalse]. We then know that [beval st b = false] and [c2 / st || st']. Recall that [b] is equivalent to [BTrue], i.e. forall [st], [beval st b = beval st BTrue]. In particular, this means that [beval st b = true], since [beval st BTrue = true]. But this is a contradiction, since [E_IfFalse] requires that [beval st b = false]. Thus, the final rule could not have been [E_IfFalse]. - ([<-]) We must show, for all [st] and [st'], that if [c1 / st || st'] then [IFB b THEN c1 ELSE c2 FI / st || st']. Since [b] is equivalent to [BTrue], we know that [beval st b] = [beval st BTrue] = [true]. Together with the assumption that [c1 / st || st'], we can apply [E_IfTrue] to derive [IFB b THEN c1 ELSE c2 FI / st || st']. [] Here is the formal version of this proof: *) Theorem IFB_true: forall b c1 c2, bequiv b BTrue -> cequiv (IFB b THEN c1 ELSE c2 FI) c1. Proof. intros b c1 c2 Hb. split; intros H. Case "->". inversion H; subst. SCase "b evaluates to true". assumption. SCase "b evaluates to false (contradiction)". unfold bequiv in Hb. simpl in Hb. rewrite Hb in H5. inversion H5. Case "<-". apply E_IfTrue; try assumption. unfold bequiv in Hb. simpl in Hb. rewrite Hb. reflexivity. Qed. (** **** Exercise: 2 stars (IFB_false) *) Theorem IFB_false: forall b c1 c2, bequiv b BFalse -> cequiv (IFB b THEN c1 ELSE c2 FI) c2. Proof. (* FILL IN HERE *) Admitted. (** [] *) (** **** Exercise: 3 stars (swap_if_branches) *) (** Show that we can swap the branches of an IF by negating its condition *) Theorem swap_if_branches: forall b e1 e2, cequiv (IFB b THEN e1 ELSE e2 FI) (IFB BNot b THEN e2 ELSE e1 FI). Proof. (* FILL IN HERE *) Admitted. (** [] *) (** *** *) (** For [WHILE] loops, we can give a similar pair of theorems. A loop whose guard is equivalent to [BFalse] is equivalent to [SKIP], while a loop whose guard is equivalent to [BTrue] is equivalent to [WHILE BTrue DO SKIP END] (or any other non-terminating program). The first of these facts is easy. *) Theorem WHILE_false : forall b c, bequiv b BFalse -> cequiv (WHILE b DO c END) SKIP. Proof. intros b c Hb. split; intros H. Case "->". inversion H; subst. SCase "E_WhileEnd". apply E_Skip. SCase "E_WhileLoop". rewrite Hb in H2. inversion H2. Case "<-". inversion H; subst. apply E_WhileEnd. rewrite Hb. reflexivity. Qed. (** **** Exercise: 2 stars, advanced, optional (WHILE_false_informal) *) (** Write an informal proof of [WHILE_false]. (* FILL IN HERE *) [] *) (** *** *) (** To prove the second fact, we need an auxiliary lemma stating that [WHILE] loops whose guards are equivalent to [BTrue] never terminate: _Lemma_: If [b] is equivalent to [BTrue], then it cannot be the case that [(WHILE b DO c END) / st || st']. _Proof_: Suppose that [(WHILE b DO c END) / st || st']. We show, by induction on a derivation of [(WHILE b DO c END) / st || st'], that this assumption leads to a contradiction. - Suppose [(WHILE b DO c END) / st || st'] is proved using rule [E_WhileEnd]. Then by assumption [beval st b = false]. But this contradicts the assumption that [b] is equivalent to [BTrue]. - Suppose [(WHILE b DO c END) / st || st'] is proved using rule [E_WhileLoop]. Then we are given the induction hypothesis that [(WHILE b DO c END) / st || st'] is contradictory, which is exactly what we are trying to prove! - Since these are the only rules that could have been used to prove [(WHILE b DO c END) / st || st'], the other cases of the induction are immediately contradictory. [] *) Lemma WHILE_true_nonterm : forall b c st st', bequiv b BTrue -> ~( (WHILE b DO c END) / st || st' ). Proof. (* WORKED IN CLASS *) intros b c st st' Hb. intros H. remember (WHILE b DO c END) as cw eqn:Heqcw. ceval_cases (induction H) Case; (* Most rules don't apply, and we can rule them out by inversion *) inversion Heqcw; subst; clear Heqcw. (* The two interesting cases are the ones for WHILE loops: *) Case "E_WhileEnd". (* contradictory -- b is always true! *) unfold bequiv in Hb. (* [rewrite] is able to instantiate the quantifier in [st] *) rewrite Hb in H. inversion H. Case "E_WhileLoop". (* immediate from the IH *) apply IHceval2. reflexivity. Qed. (** **** Exercise: 2 stars, optional (WHILE_true_nonterm_informal) *) (** Explain what the lemma [WHILE_true_nonterm] means in English. (* FILL IN HERE *) *) (** [] *) (** **** Exercise: 2 stars (WHILE_true) *) (** Prove the following theorem. _Hint_: You'll want to use [WHILE_true_nonterm] here. *) Theorem WHILE_true: forall b c, bequiv b BTrue -> cequiv (WHILE b DO c END) (WHILE BTrue DO SKIP END). Proof. (* FILL IN HERE *) Admitted. (** [] *) Theorem loop_unrolling: forall b c, cequiv (WHILE b DO c END) (IFB b THEN (c;; WHILE b DO c END) ELSE SKIP FI). Proof. (* WORKED IN CLASS *) intros b c st st'. split; intros Hce. Case "->". inversion Hce; subst. SCase "loop doesn't run". apply E_IfFalse. assumption. apply E_Skip. SCase "loop runs". apply E_IfTrue. assumption. apply E_Seq with (st' := st'0). assumption. assumption. Case "<-". inversion Hce; subst. SCase "loop runs". inversion H5; subst. apply E_WhileLoop with (st' := st'0). assumption. assumption. assumption. SCase "loop doesn't run". inversion H5; subst. apply E_WhileEnd. assumption. Qed. (** **** Exercise: 2 stars, optional (seq_assoc) *) Theorem seq_assoc : forall c1 c2 c3, cequiv ((c1;;c2);;c3) (c1;;(c2;;c3)). Proof. (* FILL IN HERE *) Admitted. (** [] *) (** ** The Functional Equivalence Axiom *) (** Finally, let's look at simple equivalences involving assignments. For example, we might expect to be able to show that [X ::= AId X] is equivalent to [SKIP]. However, when we try to show it, we get stuck in an interesting way. *) Theorem identity_assignment_first_try : forall (X:id), cequiv (X ::= AId X) SKIP. Proof. intros. split; intro H. Case "->". inversion H; subst. simpl. replace (update st X (st X)) with st. constructor. (* Stuck... *) Abort. (** Here we're stuck. The goal looks reasonable, but in fact it is not provable! If we look back at the set of lemmas we proved about [update] in the last chapter, we can see that lemma [update_same] almost does the job, but not quite: it says that the original and updated states agree at all values, but this is not the same thing as saying that they are [=] in Coq's sense! *) (** What is going on here? Recall that our states are just functions from identifiers to values. For Coq, functions are only equal when their definitions are syntactically the same, modulo simplification. (This is the only way we can legally apply the [refl_equal] constructor of the inductively defined proposition [eq]!) In practice, for functions built up by repeated uses of the [update] operation, this means that two functions can be proven equal only if they were constructed using the _same_ [update] operations, applied in the same order. In the theorem above, the sequence of updates on the first parameter [cequiv] is one longer than for the second parameter, so it is no wonder that the equality doesn't hold. *) (** *** *) (** This problem is actually quite general. If we try to prove other simple facts, such as cequiv (X ::= X + 1;; X ::= X + 1) (X ::= X + 2) or cequiv (X ::= 1;; Y ::= 2) (y ::= 2;; X ::= 1) we'll get stuck in the same way: we'll have two functions that behave the same way on all inputs, but cannot be proven to be [eq] to each other. The reasoning principle we would like to use in these situations is called _functional extensionality_: forall x, f x = g x ------------------- f = g Although this principle is not derivable in Coq's built-in logic, it is safe to add it as an additional _axiom_. *) Axiom functional_extensionality : forall {X Y: Type} {f g : X -> Y}, (forall (x: X), f x = g x) -> f = g. (** It can be shown that adding this axiom doesn't introduce any inconsistencies into Coq. (In this way, it is similar to adding one of the classical logic axioms, such as [excluded_middle].) *) (** With the benefit of this axiom we can prove our theorem. *) Theorem identity_assignment : forall (X:id), cequiv (X ::= AId X) SKIP. Proof. intros. split; intro H. Case "->". inversion H; subst. simpl. replace (update st X (st X)) with st. constructor. apply functional_extensionality. intro. rewrite update_same; reflexivity. Case "<-". inversion H; subst. assert (st' = (update st' X (st' X))). apply functional_extensionality. intro. rewrite update_same; reflexivity. rewrite H0 at 2. constructor. reflexivity. Qed. (** **** Exercise: 2 stars (assign_aequiv) *) Theorem assign_aequiv : forall X e, aequiv (AId X) e -> cequiv SKIP (X ::= e). Proof. (* FILL IN HERE *) Admitted. (** [] *) (* ####################################################### *) (** * Properties of Behavioral Equivalence *) (** We now turn to developing some of the properties of the program equivalences we have defined. *) (* ####################################################### *) (** ** Behavioral Equivalence is an Equivalence *) (** First, we verify that the equivalences on [aexps], [bexps], and [com]s really are _equivalences_ -- i.e., that they are reflexive, symmetric, and transitive. The proofs are all easy. *) Lemma refl_aequiv : forall (a : aexp), aequiv a a. Proof. intros a st. reflexivity. Qed. Lemma sym_aequiv : forall (a1 a2 : aexp), aequiv a1 a2 -> aequiv a2 a1. Proof. intros a1 a2 H. intros st. symmetry. apply H. Qed. Lemma trans_aequiv : forall (a1 a2 a3 : aexp), aequiv a1 a2 -> aequiv a2 a3 -> aequiv a1 a3. Proof. unfold aequiv. intros a1 a2 a3 H12 H23 st. rewrite (H12 st). rewrite (H23 st). reflexivity. Qed. Lemma refl_bequiv : forall (b : bexp), bequiv b b. Proof. unfold bequiv. intros b st. reflexivity. Qed. Lemma sym_bequiv : forall (b1 b2 : bexp), bequiv b1 b2 -> bequiv b2 b1. Proof. unfold bequiv. intros b1 b2 H. intros st. symmetry. apply H. Qed. Lemma trans_bequiv : forall (b1 b2 b3 : bexp), bequiv b1 b2 -> bequiv b2 b3 -> bequiv b1 b3. Proof. unfold bequiv. intros b1 b2 b3 H12 H23 st. rewrite (H12 st). rewrite (H23 st). reflexivity. Qed. Lemma refl_cequiv : forall (c : com), cequiv c c. Proof. unfold cequiv. intros c st st'. apply iff_refl. Qed. Lemma sym_cequiv : forall (c1 c2 : com), cequiv c1 c2 -> cequiv c2 c1. Proof. unfold cequiv. intros c1 c2 H st st'. assert (c1 / st || st' <-> c2 / st || st') as H'. SCase "Proof of assertion". apply H. apply iff_sym. assumption. Qed. Lemma iff_trans : forall (P1 P2 P3 : Prop), (P1 <-> P2) -> (P2 <-> P3) -> (P1 <-> P3). Proof. intros P1 P2 P3 H12 H23. inversion H12. inversion H23. split; intros A. apply H1. apply H. apply A. apply H0. apply H2. apply A. Qed. Lemma trans_cequiv : forall (c1 c2 c3 : com), cequiv c1 c2 -> cequiv c2 c3 -> cequiv c1 c3. Proof. unfold cequiv. intros c1 c2 c3 H12 H23 st st'. apply iff_trans with (c2 / st || st'). apply H12. apply H23. Qed. (* ######################################################## *) (** ** Behavioral Equivalence is a Congruence *) (** Less obviously, behavioral equivalence is also a _congruence_. That is, the equivalence of two subprograms implies the equivalence of the larger programs in which they are embedded: aequiv a1 a1' ----------------------------- cequiv (i ::= a1) (i ::= a1') cequiv c1 c1' cequiv c2 c2' ------------------------ cequiv (c1;;c2) (c1';;c2') ...and so on. (Note that we are using the inference rule notation here not as part of a definition, but simply to write down some valid implications in a readable format. We prove these implications below.) *) (** We will see a concrete example of why these congruence properties are important in the following section (in the proof of [fold_constants_com_sound]), but the main idea is that they allow us to replace a small part of a large program with an equivalent small part and know that the whole large programs are equivalent _without_ doing an explicit proof about the non-varying parts -- i.e., the "proof burden" of a small change to a large program is proportional to the size of the change, not the program. *) Theorem CAss_congruence : forall i a1 a1', aequiv a1 a1' -> cequiv (CAss i a1) (CAss i a1'). Proof. intros i a1 a2 Heqv st st'. split; intros Hceval. Case "->". inversion Hceval. subst. apply E_Ass. rewrite Heqv. reflexivity. Case "<-". inversion Hceval. subst. apply E_Ass. rewrite Heqv. reflexivity. Qed. (** The congruence property for loops is a little more interesting, since it requires induction. _Theorem_: Equivalence is a congruence for [WHILE] -- that is, if [b1] is equivalent to [b1'] and [c1] is equivalent to [c1'], then [WHILE b1 DO c1 END] is equivalent to [WHILE b1' DO c1' END]. _Proof_: Suppose [b1] is equivalent to [b1'] and [c1] is equivalent to [c1']. We must show, for every [st] and [st'], that [WHILE b1 DO c1 END / st || st'] iff [WHILE b1' DO c1' END / st || st']. We consider the two directions separately. - ([->]) We show that [WHILE b1 DO c1 END / st || st'] implies [WHILE b1' DO c1' END / st || st'], by induction on a derivation of [WHILE b1 DO c1 END / st || st']. The only nontrivial cases are when the final rule in the derivation is [E_WhileEnd] or [E_WhileLoop]. - [E_WhileEnd]: In this case, the form of the rule gives us [beval st b1 = false] and [st = st']. But then, since [b1] and [b1'] are equivalent, we have [beval st b1' = false], and [E-WhileEnd] applies, giving us [WHILE b1' DO c1' END / st || st'], as required. - [E_WhileLoop]: The form of the rule now gives us [beval st b1 = true], with [c1 / st || st'0] and [WHILE b1 DO c1 END / st'0 || st'] for some state [st'0], with the induction hypothesis [WHILE b1' DO c1' END / st'0 || st']. Since [c1] and [c1'] are equivalent, we know that [c1' / st || st'0]. And since [b1] and [b1'] are equivalent, we have [beval st b1' = true]. Now [E-WhileLoop] applies, giving us [WHILE b1' DO c1' END / st || st'], as required. - ([<-]) Similar. [] *) Theorem CWhile_congruence : forall b1 b1' c1 c1', bequiv b1 b1' -> cequiv c1 c1' -> cequiv (WHILE b1 DO c1 END) (WHILE b1' DO c1' END). Proof. (* WORKED IN CLASS *) unfold bequiv,cequiv. intros b1 b1' c1 c1' Hb1e Hc1e st st'. split; intros Hce. Case "->". remember (WHILE b1 DO c1 END) as cwhile eqn:Heqcwhile. induction Hce; inversion Heqcwhile; subst. SCase "E_WhileEnd". apply E_WhileEnd. rewrite <- Hb1e. apply H. SCase "E_WhileLoop". apply E_WhileLoop with (st' := st'). SSCase "show loop runs". rewrite <- Hb1e. apply H. SSCase "body execution". apply (Hc1e st st'). apply Hce1. SSCase "subsequent loop execution". apply IHHce2. reflexivity. Case "<-". remember (WHILE b1' DO c1' END) as c'while eqn:Heqc'while. induction Hce; inversion Heqc'while; subst. SCase "E_WhileEnd". apply E_WhileEnd. rewrite -> Hb1e. apply H. SCase "E_WhileLoop". apply E_WhileLoop with (st' := st'). SSCase "show loop runs". rewrite -> Hb1e. apply H. SSCase "body execution". apply (Hc1e st st'). apply Hce1. SSCase "subsequent loop execution". apply IHHce2. reflexivity. Qed. (** **** Exercise: 3 stars, optional (CSeq_congruence) *) Theorem CSeq_congruence : forall c1 c1' c2 c2', cequiv c1 c1' -> cequiv c2 c2' -> cequiv (c1;;c2) (c1';;c2'). Proof. (* FILL IN HERE *) Admitted. (** [] *) (** **** Exercise: 3 stars (CIf_congruence) *) Theorem CIf_congruence : forall b b' c1 c1' c2 c2', bequiv b b' -> cequiv c1 c1' -> cequiv c2 c2' -> cequiv (IFB b THEN c1 ELSE c2 FI) (IFB b' THEN c1' ELSE c2' FI). Proof. (* FILL IN HERE *) Admitted. (** [] *) (** *** *) (** For example, here are two equivalent programs and a proof of their equivalence... *) Example congruence_example: cequiv (* Program 1: *) (X ::= ANum 0;; IFB (BEq (AId X) (ANum 0)) THEN Y ::= ANum 0 ELSE Y ::= ANum 42 FI) (* Program 2: *) (X ::= ANum 0;; IFB (BEq (AId X) (ANum 0)) THEN Y ::= AMinus (AId X) (AId X) (* <--- changed here *) ELSE Y ::= ANum 42 FI). Proof. apply CSeq_congruence. apply refl_cequiv. apply CIf_congruence. apply refl_bequiv. apply CAss_congruence. unfold aequiv. simpl. symmetry. apply minus_diag. apply refl_cequiv. Qed. (* ####################################################### *) (** * Program Transformations *) (** A _program transformation_ is a function that takes a program as input and produces some variant of the program as its output. Compiler optimizations such as constant folding are a canonical example, but there are many others. *) (** A program transformation is _sound_ if it preserves the behavior of the original program. We can define a notion of soundness for translations of [aexp]s, [bexp]s, and [com]s. *) Definition atrans_sound (atrans : aexp -> aexp) : Prop := forall (a : aexp), aequiv a (atrans a). Definition btrans_sound (btrans : bexp -> bexp) : Prop := forall (b : bexp), bequiv b (btrans b). Definition ctrans_sound (ctrans : com -> com) : Prop := forall (c : com), cequiv c (ctrans c). (* ######################################################## *) (** ** The Constant-Folding Transformation *) (** An expression is _constant_ when it contains no variable references. Constant folding is an optimization that finds constant expressions and replaces them by their values. *) Fixpoint fold_constants_aexp (a : aexp) : aexp := match a with | ANum n => ANum n | AId i => AId i | APlus a1 a2 => match (fold_constants_aexp a1, fold_constants_aexp a2) with | (ANum n1, ANum n2) => ANum (n1 + n2) | (a1', a2') => APlus a1' a2' end | AMinus a1 a2 => match (fold_constants_aexp a1, fold_constants_aexp a2) with | (ANum n1, ANum n2) => ANum (n1 - n2) | (a1', a2') => AMinus a1' a2' end | AMult a1 a2 => match (fold_constants_aexp a1, fold_constants_aexp a2) with | (ANum n1, ANum n2) => ANum (n1 * n2) | (a1', a2') => AMult a1' a2' end end. Example fold_aexp_ex1 : fold_constants_aexp (AMult (APlus (ANum 1) (ANum 2)) (AId X)) = AMult (ANum 3) (AId X). Proof. reflexivity. Qed. (** Note that this version of constant folding doesn't eliminate trivial additions, etc. -- we are focusing attention on a single optimization for the sake of simplicity. It is not hard to incorporate other ways of simplifying expressions; the definitions and proofs just get longer. *) Example fold_aexp_ex2 : fold_constants_aexp (AMinus (AId X) (APlus (AMult (ANum 0) (ANum 6)) (AId Y))) = AMinus (AId X) (APlus (ANum 0) (AId Y)). Proof. reflexivity. Qed. (** *** *) (** Not only can we lift [fold_constants_aexp] to [bexp]s (in the [BEq] and [BLe] cases), we can also find constant _boolean_ expressions and reduce them in-place. *) Fixpoint fold_constants_bexp (b : bexp) : bexp := match b with | BTrue => BTrue | BFalse => BFalse | BEq a1 a2 => match (fold_constants_aexp a1, fold_constants_aexp a2) with | (ANum n1, ANum n2) => if beq_nat n1 n2 then BTrue else BFalse | (a1', a2') => BEq a1' a2' end | BLe a1 a2 => match (fold_constants_aexp a1, fold_constants_aexp a2) with | (ANum n1, ANum n2) => if ble_nat n1 n2 then BTrue else BFalse | (a1', a2') => BLe a1' a2' end | BNot b1 => match (fold_constants_bexp b1) with | BTrue => BFalse | BFalse => BTrue | b1' => BNot b1' end | BAnd b1 b2 => match (fold_constants_bexp b1, fold_constants_bexp b2) with | (BTrue, BTrue) => BTrue | (BTrue, BFalse) => BFalse | (BFalse, BTrue) => BFalse | (BFalse, BFalse) => BFalse | (b1', b2') => BAnd b1' b2' end end. Example fold_bexp_ex1 : fold_constants_bexp (BAnd BTrue (BNot (BAnd BFalse BTrue))) = BTrue. Proof. reflexivity. Qed. Example fold_bexp_ex2 : fold_constants_bexp (BAnd (BEq (AId X) (AId Y)) (BEq (ANum 0) (AMinus (ANum 2) (APlus (ANum 1) (ANum 1))))) = BAnd (BEq (AId X) (AId Y)) BTrue. Proof. reflexivity. Qed. (** *** *) (** To fold constants in a command, we apply the appropriate folding functions on all embedded expressions. *) Fixpoint fold_constants_com (c : com) : com := match c with | SKIP => SKIP | i ::= a => CAss i (fold_constants_aexp a) | c1 ;; c2 => (fold_constants_com c1) ;; (fold_constants_com c2) | IFB b THEN c1 ELSE c2 FI => match fold_constants_bexp b with | BTrue => fold_constants_com c1 | BFalse => fold_constants_com c2 | b' => IFB b' THEN fold_constants_com c1 ELSE fold_constants_com c2 FI end | WHILE b DO c END => match fold_constants_bexp b with | BTrue => WHILE BTrue DO SKIP END | BFalse => SKIP | b' => WHILE b' DO (fold_constants_com c) END end end. (** *** *) Example fold_com_ex1 : fold_constants_com (* Original program: *) (X ::= APlus (ANum 4) (ANum 5);; Y ::= AMinus (AId X) (ANum 3);; IFB BEq (AMinus (AId X) (AId Y)) (APlus (ANum 2) (ANum 4)) THEN SKIP ELSE Y ::= ANum 0 FI;; IFB BLe (ANum 0) (AMinus (ANum 4) (APlus (ANum 2) (ANum 1))) THEN Y ::= ANum 0 ELSE SKIP FI;; WHILE BEq (AId Y) (ANum 0) DO X ::= APlus (AId X) (ANum 1) END) = (* After constant folding: *) (X ::= ANum 9;; Y ::= AMinus (AId X) (ANum 3);; IFB BEq (AMinus (AId X) (AId Y)) (ANum 6) THEN SKIP ELSE (Y ::= ANum 0) FI;; Y ::= ANum 0;; WHILE BEq (AId Y) (ANum 0) DO X ::= APlus (AId X) (ANum 1) END). Proof. reflexivity. Qed. (* ################################################### *) (** ** Soundness of Constant Folding *) (** Now we need to show that what we've done is correct. *) (** Here's the proof for arithmetic expressions: *) Theorem fold_constants_aexp_sound : atrans_sound fold_constants_aexp. Proof. unfold atrans_sound. intros a. unfold aequiv. intros st. aexp_cases (induction a) Case; simpl; (* ANum and AId follow immediately *) try reflexivity; (* APlus, AMinus, and AMult follow from the IH and the observation that aeval st (APlus a1 a2) = ANum ((aeval st a1) + (aeval st a2)) = aeval st (ANum ((aeval st a1) + (aeval st a2))) (and similarly for AMinus/minus and AMult/mult) *) try (destruct (fold_constants_aexp a1); destruct (fold_constants_aexp a2); rewrite IHa1; rewrite IHa2; reflexivity). Qed. (** **** Exercise: 3 stars, optional (fold_bexp_Eq_informal) *) (** Here is an informal proof of the [BEq] case of the soundness argument for boolean expression constant folding. Read it carefully and compare it to the formal proof that follows. Then fill in the [BLe] case of the formal proof (without looking at the [BEq] case, if possible). _Theorem_: The constant folding function for booleans, [fold_constants_bexp], is sound. _Proof_: We must show that [b] is equivalent to [fold_constants_bexp], for all boolean expressions [b]. Proceed by induction on [b]. We show just the case where [b] has the form [BEq a1 a2]. In this case, we must show beval st (BEq a1 a2) = beval st (fold_constants_bexp (BEq a1 a2)). There are two cases to consider: - First, suppose [fold_constants_aexp a1 = ANum n1] and [fold_constants_aexp a2 = ANum n2] for some [n1] and [n2]. In this case, we have fold_constants_bexp (BEq a1 a2) = if beq_nat n1 n2 then BTrue else BFalse and beval st (BEq a1 a2) = beq_nat (aeval st a1) (aeval st a2). By the soundness of constant folding for arithmetic expressions (Lemma [fold_constants_aexp_sound]), we know aeval st a1 = aeval st (fold_constants_aexp a1) = aeval st (ANum n1) = n1 and aeval st a2 = aeval st (fold_constants_aexp a2) = aeval st (ANum n2) = n2, so beval st (BEq a1 a2) = beq_nat (aeval a1) (aeval a2) = beq_nat n1 n2. Also, it is easy to see (by considering the cases [n1 = n2] and [n1 <> n2] separately) that beval st (if beq_nat n1 n2 then BTrue else BFalse) = if beq_nat n1 n2 then beval st BTrue else beval st BFalse = if beq_nat n1 n2 then true else false = beq_nat n1 n2. So beval st (BEq a1 a2) = beq_nat n1 n2. = beval st (if beq_nat n1 n2 then BTrue else BFalse), ]] as required. - Otherwise, one of [fold_constants_aexp a1] and [fold_constants_aexp a2] is not a constant. In this case, we must show beval st (BEq a1 a2) = beval st (BEq (fold_constants_aexp a1) (fold_constants_aexp a2)), which, by the definition of [beval], is the same as showing beq_nat (aeval st a1) (aeval st a2) = beq_nat (aeval st (fold_constants_aexp a1)) (aeval st (fold_constants_aexp a2)). But the soundness of constant folding for arithmetic expressions ([fold_constants_aexp_sound]) gives us aeval st a1 = aeval st (fold_constants_aexp a1) aeval st a2 = aeval st (fold_constants_aexp a2), completing the case. [] *) Theorem fold_constants_bexp_sound: btrans_sound fold_constants_bexp. Proof. unfold btrans_sound. intros b. unfold bequiv. intros st. bexp_cases (induction b) Case; (* BTrue and BFalse are immediate *) try reflexivity. Case "BEq". (* Doing induction when there are a lot of constructors makes specifying variable names a chore, but Coq doesn't always choose nice variable names. We can rename entries in the context with the [rename] tactic: [rename a into a1] will change [a] to [a1] in the current goal and context. *) rename a into a1. rename a0 into a2. simpl. remember (fold_constants_aexp a1) as a1' eqn:Heqa1'. remember (fold_constants_aexp a2) as a2' eqn:Heqa2'. replace (aeval st a1) with (aeval st a1') by (subst a1'; rewrite <- fold_constants_aexp_sound; reflexivity). replace (aeval st a2) with (aeval st a2') by (subst a2'; rewrite <- fold_constants_aexp_sound; reflexivity). destruct a1'; destruct a2'; try reflexivity. (* The only interesting case is when both a1 and a2 become constants after folding *) simpl. destruct (beq_nat n n0); reflexivity. Case "BLe". (* FILL IN HERE *) admit. Case "BNot". simpl. remember (fold_constants_bexp b) as b' eqn:Heqb'. rewrite IHb. destruct b'; reflexivity. Case "BAnd". simpl. remember (fold_constants_bexp b1) as b1' eqn:Heqb1'. remember (fold_constants_bexp b2) as b2' eqn:Heqb2'. rewrite IHb1. rewrite IHb2. destruct b1'; destruct b2'; reflexivity. Qed. (** [] *) (** **** Exercise: 3 stars (fold_constants_com_sound) *) (** Complete the [WHILE] case of the following proof. *) Theorem fold_constants_com_sound : ctrans_sound fold_constants_com. Proof. unfold ctrans_sound. intros c. com_cases (induction c) Case; simpl. Case "SKIP". apply refl_cequiv. Case "::=". apply CAss_congruence. apply fold_constants_aexp_sound. Case ";;". apply CSeq_congruence; assumption. Case "IFB". assert (bequiv b (fold_constants_bexp b)). SCase "Pf of assertion". apply fold_constants_bexp_sound. destruct (fold_constants_bexp b) eqn:Heqb; (* If the optimization doesn't eliminate the if, then the result is easy to prove from the IH and fold_constants_bexp_sound *) try (apply CIf_congruence; assumption). SCase "b always true". apply trans_cequiv with c1; try assumption. apply IFB_true; assumption. SCase "b always false". apply trans_cequiv with c2; try assumption. apply IFB_false; assumption. Case "WHILE". (* FILL IN HERE *) Admitted. (** [] *) (* ########################################################## *) (** *** Soundness of (0 + n) Elimination, Redux *) (** **** Exercise: 4 stars, advanced, optional (optimize_0plus) *) (** Recall the definition [optimize_0plus] from Imp.v: Fixpoint optimize_0plus (e:aexp) : aexp := match e with | ANum n => ANum n | APlus (ANum 0) e2 => optimize_0plus e2 | APlus e1 e2 => APlus (optimize_0plus e1) (optimize_0plus e2) | AMinus e1 e2 => AMinus (optimize_0plus e1) (optimize_0plus e2) | AMult e1 e2 => AMult (optimize_0plus e1) (optimize_0plus e2) end. Note that this function is defined over the old [aexp]s, without states. Write a new version of this function that accounts for variables, and analogous ones for [bexp]s and commands: optimize_0plus_aexp optimize_0plus_bexp optimize_0plus_com Prove that these three functions are sound, as we did for [fold_constants_*]. (Make sure you use the congruence lemmas in the proof of [optimize_0plus_com] -- otherwise it will be _long_!) Then define an optimizer on commands that first folds constants (using [fold_constants_com]) and then eliminates [0 + n] terms (using [optimize_0plus_com]). - Give a meaningful example of this optimizer's output. - Prove that the optimizer is sound. (This part should be _very_ easy.) *) (* FILL IN HERE *) (** [] *) (* ####################################################### *) (** * Proving That Programs Are _Not_ Equivalent *) (** Suppose that [c1] is a command of the form [X ::= a1;; Y ::= a2] and [c2] is the command [X ::= a1;; Y ::= a2'], where [a2'] is formed by substituting [a1] for all occurrences of [X] in [a2]. For example, [c1] and [c2] might be: c1 = (X ::= 42 + 53;; Y ::= Y + X) c2 = (X ::= 42 + 53;; Y ::= Y + (42 + 53)) Clearly, this _particular_ [c1] and [c2] are equivalent. Is this true in general? *) (** We will see in a moment that it is not, but it is worthwhile to pause, now, and see if you can find a counter-example on your own. *) (** Here, formally, is the function that substitutes an arithmetic expression for each occurrence of a given variable in another expression: *) Fixpoint subst_aexp (i : id) (u : aexp) (a : aexp) : aexp := match a with | ANum n => ANum n | AId i' => if eq_id_dec i i' then u else AId i' | APlus a1 a2 => APlus (subst_aexp i u a1) (subst_aexp i u a2) | AMinus a1 a2 => AMinus (subst_aexp i u a1) (subst_aexp i u a2) | AMult a1 a2 => AMult (subst_aexp i u a1) (subst_aexp i u a2) end. Example subst_aexp_ex : subst_aexp X (APlus (ANum 42) (ANum 53)) (APlus (AId Y) (AId X)) = (APlus (AId Y) (APlus (ANum 42) (ANum 53))). Proof. reflexivity. Qed. (** And here is the property we are interested in, expressing the claim that commands [c1] and [c2] as described above are always equivalent. *) Definition subst_equiv_property := forall i1 i2 a1 a2, cequiv (i1 ::= a1;; i2 ::= a2) (i1 ::= a1;; i2 ::= subst_aexp i1 a1 a2). (** *** *) (** Sadly, the property does _not_ always hold. _Theorem_: It is not the case that, for all [i1], [i2], [a1], and [a2], cequiv (i1 ::= a1;; i2 ::= a2) (i1 ::= a1;; i2 ::= subst_aexp i1 a1 a2). ]] _Proof_: Suppose, for a contradiction, that for all [i1], [i2], [a1], and [a2], we have cequiv (i1 ::= a1;; i2 ::= a2) (i1 ::= a1;; i2 ::= subst_aexp i1 a1 a2). Consider the following program: X ::= APlus (AId X) (ANum 1);; Y ::= AId X Note that (X ::= APlus (AId X) (ANum 1);; Y ::= AId X) / empty_state || st1, where [st1 = { X |-> 1, Y |-> 1 }]. By our assumption, we know that cequiv (X ::= APlus (AId X) (ANum 1);; Y ::= AId X) (X ::= APlus (AId X) (ANum 1);; Y ::= APlus (AId X) (ANum 1)) so, by the definition of [cequiv], we have (X ::= APlus (AId X) (ANum 1);; Y ::= APlus (AId X) (ANum 1)) / empty_state || st1. But we can also derive (X ::= APlus (AId X) (ANum 1);; Y ::= APlus (AId X) (ANum 1)) / empty_state || st2, where [st2 = { X |-> 1, Y |-> 2 }]. Note that [st1 <> st2]; this is a contradiction, since [ceval] is deterministic! [] *) Theorem subst_inequiv : ~ subst_equiv_property. Proof. unfold subst_equiv_property. intros Contra. (* Here is the counterexample: assuming that [subst_equiv_property] holds allows us to prove that these two programs are equivalent... *) remember (X ::= APlus (AId X) (ANum 1);; Y ::= AId X) as c1. remember (X ::= APlus (AId X) (ANum 1);; Y ::= APlus (AId X) (ANum 1)) as c2. assert (cequiv c1 c2) by (subst; apply Contra). (* ... allows us to show that the command [c2] can terminate in two different final states: st1 = {X |-> 1, Y |-> 1} st2 = {X |-> 1, Y |-> 2}. *) remember (update (update empty_state X 1) Y 1) as st1. remember (update (update empty_state X 1) Y 2) as st2. assert (H1: c1 / empty_state || st1); assert (H2: c2 / empty_state || st2); try (subst; apply E_Seq with (st' := (update empty_state X 1)); apply E_Ass; reflexivity). apply H in H1. (* Finally, we use the fact that evaluation is deterministic to obtain a contradiction. *) assert (Hcontra: st1 = st2) by (apply (ceval_deterministic c2 empty_state); assumption). assert (Hcontra': st1 Y = st2 Y) by (rewrite Hcontra; reflexivity). subst. inversion Hcontra'. Qed. (** **** Exercise: 4 stars, optional (better_subst_equiv) *) (** The equivalence we had in mind above was not complete nonsense -- it was actually almost right. To make it correct, we just need to exclude the case where the variable [X] occurs in the right-hand-side of the first assignment statement. *) Inductive var_not_used_in_aexp (X:id) : aexp -> Prop := | VNUNum: forall n, var_not_used_in_aexp X (ANum n) | VNUId: forall Y, X <> Y -> var_not_used_in_aexp X (AId Y) | VNUPlus: forall a1 a2, var_not_used_in_aexp X a1 -> var_not_used_in_aexp X a2 -> var_not_used_in_aexp X (APlus a1 a2) | VNUMinus: forall a1 a2, var_not_used_in_aexp X a1 -> var_not_used_in_aexp X a2 -> var_not_used_in_aexp X (AMinus a1 a2) | VNUMult: forall a1 a2, var_not_used_in_aexp X a1 -> var_not_used_in_aexp X a2 -> var_not_used_in_aexp X (AMult a1 a2). Lemma aeval_weakening : forall i st a ni, var_not_used_in_aexp i a -> aeval (update st i ni) a = aeval st a. Proof. (* FILL IN HERE *) Admitted. (** Using [var_not_used_in_aexp], formalize and prove a correct verson of [subst_equiv_property]. *) (* FILL IN HERE *) (** [] *) (** **** Exercise: 3 stars, optional (inequiv_exercise) *) (** Prove that an infinite loop is not equivalent to [SKIP] *) Theorem inequiv_exercise: ~ cequiv (WHILE BTrue DO SKIP END) SKIP. Proof. (* FILL IN HERE *) Admitted. (** [] *) (** * Extended exercise: Non-deterministic Imp *) (** As we have seen (in theorem [ceval_deterministic] in the Imp chapter), Imp's evaluation relation is deterministic. However, _non_-determinism is an important part of the definition of many real programming languages. For example, in many imperative languages (such as C and its relatives), the order in which function arguments are evaluated is unspecified. The program fragment x = 0;; f(++x, x) might call [f] with arguments [(1, 0)] or [(1, 1)], depending how the compiler chooses to order things. This can be a little confusing for programmers, but it gives the compiler writer useful freedom. In this exercise, we will extend Imp with a simple non-deterministic command and study how this change affects program equivalence. The new command has the syntax [HAVOC X], where [X] is an identifier. The effect of executing [HAVOC X] is to assign an _arbitrary_ number to the variable [X], non-deterministically. For example, after executing the program: HAVOC Y;; Z ::= Y * 2 the value of [Y] can be any number, while the value of [Z] is twice that of [Y] (so [Z] is always even). Note that we are not saying anything about the _probabilities_ of the outcomes -- just that there are (infinitely) many different outcomes that can possibly happen after executing this non-deterministic code. In a sense a variable on which we do [HAVOC] roughly corresponds to an unitialized variable in the C programming language. After the [HAVOC] the variable holds a fixed but arbitrary number. Most sources of nondeterminism in language definitions are there precisely because programmers don't care which choice is made (and so it is good to leave it open to the compiler to choose whichever will run faster). We call this new language _Himp_ (``Imp extended with [HAVOC]''). *) Module Himp. (** To formalize the language, we first add a clause to the definition of commands. *) Inductive com : Type := | CSkip : com | CAss : id -> aexp -> com | CSeq : com -> com -> com | CIf : bexp -> com -> com -> com | CWhile : bexp -> com -> com | CHavoc : id -> com. (* <---- new *) Tactic Notation "com_cases" tactic(first) ident(c) := first; [ Case_aux c "SKIP" | Case_aux c "::=" | Case_aux c ";;" | Case_aux c "IFB" | Case_aux c "WHILE" | Case_aux c "HAVOC" ]. Notation "'SKIP'" := CSkip. Notation "X '::=' a" := (CAss X a) (at level 60). Notation "c1 ;; c2" := (CSeq c1 c2) (at level 80, right associativity). Notation "'WHILE' b 'DO' c 'END'" := (CWhile b c) (at level 80, right associativity). Notation "'IFB' e1 'THEN' e2 'ELSE' e3 'FI'" := (CIf e1 e2 e3) (at level 80, right associativity). Notation "'HAVOC' l" := (CHavoc l) (at level 60). (** **** Exercise: 2 stars (himp_ceval) *) (** Now, we must extend the operational semantics. We have provided a template for the [ceval] relation below, specifying the big-step semantics. What rule(s) must be added to the definition of [ceval] to formalize the behavior of the [HAVOC] command? *) Reserved Notation "c1 '/' st '||' st'" (at level 40, st at level 39). Inductive ceval : com -> state -> state -> Prop := | E_Skip : forall st : state, SKIP / st || st | E_Ass : forall (st : state) (a1 : aexp) (n : nat) (X : id), aeval st a1 = n -> (X ::= a1) / st || update st X n | E_Seq : forall (c1 c2 : com) (st st' st'' : state), c1 / st || st' -> c2 / st' || st'' -> (c1 ;; c2) / st || st'' | E_IfTrue : forall (st st' : state) (b1 : bexp) (c1 c2 : com), beval st b1 = true -> c1 / st || st' -> (IFB b1 THEN c1 ELSE c2 FI) / st || st' | E_IfFalse : forall (st st' : state) (b1 : bexp) (c1 c2 : com), beval st b1 = false -> c2 / st || st' -> (IFB b1 THEN c1 ELSE c2 FI) / st || st' | E_WhileEnd : forall (b1 : bexp) (st : state) (c1 : com), beval st b1 = false -> (WHILE b1 DO c1 END) / st || st | E_WhileLoop : forall (st st' st'' : state) (b1 : bexp) (c1 : com), beval st b1 = true -> c1 / st || st' -> (WHILE b1 DO c1 END) / st' || st'' -> (WHILE b1 DO c1 END) / st || st'' (* FILL IN HERE *) where "c1 '/' st '||' st'" := (ceval c1 st st'). Tactic Notation "ceval_cases" tactic(first) ident(c) := first; [ Case_aux c "E_Skip" | Case_aux c "E_Ass" | Case_aux c "E_Seq" | Case_aux c "E_IfTrue" | Case_aux c "E_IfFalse" | Case_aux c "E_WhileEnd" | Case_aux c "E_WhileLoop" (* FILL IN HERE *) ]. (** As a sanity check, the following claims should be provable for your definition: *) Example havoc_example1 : (HAVOC X) / empty_state || update empty_state X 0. Proof. (* FILL IN HERE *) Admitted. Example havoc_example2 : (SKIP;; HAVOC Z) / empty_state || update empty_state Z 42. Proof. (* FILL IN HERE *) Admitted. (** [] *) (** Finally, we repeat the definition of command equivalence from above: *) Definition cequiv (c1 c2 : com) : Prop := forall st st' : state, c1 / st || st' <-> c2 / st || st'. (** This definition still makes perfect sense in the case of always terminating programs, so let's apply it to prove some non-deterministic programs equivalent or non-equivalent. *) (** **** Exercise: 3 stars (havoc_swap) *) (** Are the following two programs equivalent? *) Definition pXY := HAVOC X;; HAVOC Y. Definition pYX := HAVOC Y;; HAVOC X. (** If you think they are equivalent, prove it. If you think they are not, prove that. *) Theorem pXY_cequiv_pYX : cequiv pXY pYX \/ ~cequiv pXY pYX. Proof. (* FILL IN HERE *) Admitted. (** [] *) (** **** Exercise: 4 stars, optional (havoc_copy) *) (** Are the following two programs equivalent? *) Definition ptwice := HAVOC X;; HAVOC Y. Definition pcopy := HAVOC X;; Y ::= AId X. (** If you think they are equivalent, then prove it. If you think they are not, then prove that. (Hint: You may find the [assert] tactic useful.) *) Theorem ptwice_cequiv_pcopy : cequiv ptwice pcopy \/ ~cequiv ptwice pcopy. Proof. (* FILL IN HERE *) Admitted. (** [] *) (** The definition of program equivalence we are using here has some subtle consequences on programs that may loop forever. What [cequiv] says is that the set of possible _terminating_ outcomes of two equivalent programs is the same. However, in a language with non-determinism, like Himp, some programs always terminate, some programs always diverge, and some programs can non-deterministically terminate in some runs and diverge in others. The final part of the following exercise illustrates this phenomenon. *) (** **** Exercise: 5 stars, advanced (p1_p2_equiv) *) (** Prove that p1 and p2 are equivalent. In this and the following exercises, try to understand why the [cequiv] definition has the behavior it has on these examples. *) Definition p1 : com := WHILE (BNot (BEq (AId X) (ANum 0))) DO HAVOC Y;; X ::= APlus (AId X) (ANum 1) END. Definition p2 : com := WHILE (BNot (BEq (AId X) (ANum 0))) DO SKIP END. (** Intuitively, the programs have the same termination behavior: either they loop forever, or they terminate in the same state they started in. We can capture the termination behavior of p1 and p2 individually with these lemmas: *) Lemma p1_may_diverge : forall st st', st X <> 0 -> ~ p1 / st || st'. Proof. (* FILL IN HERE *) Admitted. Lemma p2_may_diverge : forall st st', st X <> 0 -> ~ p2 / st || st'. Proof. (* FILL IN HERE *) Admitted. (** You should use these lemmas to prove that p1 and p2 are actually equivalent. *) Theorem p1_p2_equiv : cequiv p1 p2. Proof. (* FILL IN HERE *) Admitted. (** [] *) (** **** Exercise: 4 stars, advanced (p3_p4_inquiv) *) (** Prove that the following programs are _not_ equivalent. *) Definition p3 : com := Z ::= ANum 1;; WHILE (BNot (BEq (AId X) (ANum 0))) DO HAVOC X;; HAVOC Z END. Definition p4 : com := X ::= (ANum 0);; Z ::= (ANum 1). Theorem p3_p4_inequiv : ~ cequiv p3 p4. Proof. (* FILL IN HERE *) Admitted. (** [] *) (** **** Exercise: 5 stars, advanced, optional (p5_p6_equiv) *) Definition p5 : com := WHILE (BNot (BEq (AId X) (ANum 1))) DO HAVOC X END. Definition p6 : com := X ::= ANum 1. Theorem p5_p6_equiv : cequiv p5 p6. Proof. (* FILL IN HERE *) Admitted. (** [] *) End Himp. (* ####################################################### *) (** * Doing Without Extensionality (Advanced) *) (** Purists might object to using the [functional_extensionality] axiom. In general, it can be quite dangerous to add axioms, particularly several at once (as they may be mutually inconsistent). In fact, [functional_extensionality] and [excluded_middle] can both be assumed without any problems, but some Coq users prefer to avoid such "heavyweight" general techniques, and instead craft solutions for specific problems that stay within Coq's standard logic. For our particular problem here, rather than extending the definition of equality to do what we want on functions representing states, we could instead give an explicit notion of _equivalence_ on states. For example: *) Definition stequiv (st1 st2 : state) : Prop := forall (X:id), st1 X = st2 X. Notation "st1 '~' st2" := (stequiv st1 st2) (at level 30). (** It is easy to prove that [stequiv] is an _equivalence_ (i.e., it is reflexive, symmetric, and transitive), so it partitions the set of all states into equivalence classes. *) (** **** Exercise: 1 star, optional (stequiv_refl) *) Lemma stequiv_refl : forall (st : state), st ~ st. Proof. (* FILL IN HERE *) Admitted. (** [] *) (** **** Exercise: 1 star, optional (stequiv_sym) *) Lemma stequiv_sym : forall (st1 st2 : state), st1 ~ st2 -> st2 ~ st1. Proof. (* FILL IN HERE *) Admitted. (** [] *) (** **** Exercise: 1 star, optional (stequiv_trans) *) Lemma stequiv_trans : forall (st1 st2 st3 : state), st1 ~ st2 -> st2 ~ st3 -> st1 ~ st3. Proof. (* FILL IN HERE *) Admitted. (** [] *) (** Another useful fact... *) (** **** Exercise: 1 star, optional (stequiv_update) *) Lemma stequiv_update : forall (st1 st2 : state), st1 ~ st2 -> forall (X:id) (n:nat), update st1 X n ~ update st2 X n. Proof. (* FILL IN HERE *) Admitted. (** [] *) (** It is then straightforward to show that [aeval] and [beval] behave uniformly on all members of an equivalence class: *) (** **** Exercise: 2 stars, optional (stequiv_aeval) *) Lemma stequiv_aeval : forall (st1 st2 : state), st1 ~ st2 -> forall (a:aexp), aeval st1 a = aeval st2 a. Proof. (* FILL IN HERE *) Admitted. (** [] *) (** **** Exercise: 2 stars, optional (stequiv_beval) *) Lemma stequiv_beval : forall (st1 st2 : state), st1 ~ st2 -> forall (b:bexp), beval st1 b = beval st2 b. Proof. (* FILL IN HERE *) Admitted. (** [] *) (** We can also characterize the behavior of [ceval] on equivalent states (this result is a bit more complicated to write down because [ceval] is a relation). *) Lemma stequiv_ceval: forall (st1 st2 : state), st1 ~ st2 -> forall (c: com) (st1': state), (c / st1 || st1') -> exists st2' : state, ((c / st2 || st2') /\ st1' ~ st2'). Proof. intros st1 st2 STEQV c st1' CEV1. generalize dependent st2. induction CEV1; intros st2 STEQV. Case "SKIP". exists st2. split. constructor. assumption. Case ":=". exists (update st2 x n). split. constructor. rewrite <- H. symmetry. apply stequiv_aeval. assumption. apply stequiv_update. assumption. Case ";". destruct (IHCEV1_1 st2 STEQV) as [st2' [P1 EQV1]]. destruct (IHCEV1_2 st2' EQV1) as [st2'' [P2 EQV2]]. exists st2''. split. apply E_Seq with st2'; assumption. assumption. Case "IfTrue". destruct (IHCEV1 st2 STEQV) as [st2' [P EQV]]. exists st2'. split. apply E_IfTrue. rewrite <- H. symmetry. apply stequiv_beval. assumption. assumption. assumption. Case "IfFalse". destruct (IHCEV1 st2 STEQV) as [st2' [P EQV]]. exists st2'. split. apply E_IfFalse. rewrite <- H. symmetry. apply stequiv_beval. assumption. assumption. assumption. Case "WhileEnd". exists st2. split. apply E_WhileEnd. rewrite <- H. symmetry. apply stequiv_beval. assumption. assumption. Case "WhileLoop". destruct (IHCEV1_1 st2 STEQV) as [st2' [P1 EQV1]]. destruct (IHCEV1_2 st2' EQV1) as [st2'' [P2 EQV2]]. exists st2''. split. apply E_WhileLoop with st2'. rewrite <- H. symmetry. apply stequiv_beval. assumption. assumption. assumption. assumption. Qed. (** Now we need to redefine [cequiv] to use [~] instead of [=]. It is not completely trivial to do this in a way that keeps the definition simple and symmetric, but here is one approach (thanks to Andrew McCreight). We first define a looser variant of [||] that "folds in" the notion of equivalence. *) Reserved Notation "c1 '/' st '||'' st'" (at level 40, st at level 39). Inductive ceval' : com -> state -> state -> Prop := | E_equiv : forall c st st' st'', c / st || st' -> st' ~ st'' -> c / st ||' st'' where "c1 '/' st '||'' st'" := (ceval' c1 st st'). (** Now the revised definition of [cequiv'] looks familiar: *) Definition cequiv' (c1 c2 : com) : Prop := forall (st st' : state), (c1 / st ||' st') <-> (c2 / st ||' st'). (** A sanity check shows that the original notion of command equivalence is at least as strong as this new one. (The converse is not true, naturally.) *) Lemma cequiv__cequiv' : forall (c1 c2: com), cequiv c1 c2 -> cequiv' c1 c2. Proof. unfold cequiv, cequiv'; split; intros. inversion H0 ; subst. apply E_equiv with st'0. apply (H st st'0); assumption. assumption. inversion H0 ; subst. apply E_equiv with st'0. apply (H st st'0). assumption. assumption. Qed. (** **** Exercise: 2 stars, optional (identity_assignment') *) (** Finally, here is our example once more... (You can complete the proof.) *) Example identity_assignment' : cequiv' SKIP (X ::= AId X). Proof. unfold cequiv'. intros. split; intros. Case "->". inversion H; subst; clear H. inversion H0; subst. apply E_equiv with (update st'0 X (st'0 X)). constructor. reflexivity. apply stequiv_trans with st'0. unfold stequiv. intros. apply update_same. reflexivity. assumption. Case "<-". (* FILL IN HERE *) Admitted. (** [] *) (** On the whole, this explicit equivalence approach is considerably harder to work with than relying on functional extensionality. (Coq does have an advanced mechanism called "setoids" that makes working with equivalences somewhat easier, by allowing them to be registered with the system so that standard rewriting tactics work for them almost as well as for equalities.) But it is worth knowing about, because it applies even in situations where the equivalence in question is _not_ over functions. For example, if we chose to represent state mappings as binary search trees, we would need to use an explicit equivalence of this kind. *) (* ####################################################### *) (** * Additional Exercises *) (** **** Exercise: 4 stars, optional (for_while_equiv) *) (** This exercise extends the optional [add_for_loop] exercise from Imp.v, where you were asked to extend the language of commands with C-style [for] loops. Prove that the command: for (c1 ; b ; c2) { c3 } is equivalent to: c1 ; WHILE b DO c3 ; c2 END *) (* FILL IN HERE *) (** [] *) (** **** Exercise: 3 stars, optional (swap_noninterfering_assignments) *) Theorem swap_noninterfering_assignments: forall l1 l2 a1 a2, l1 <> l2 -> var_not_used_in_aexp l1 a2 -> var_not_used_in_aexp l2 a1 -> cequiv (l1 ::= a1;; l2 ::= a2) (l2 ::= a2;; l1 ::= a1). Proof. (* Hint: You'll need [functional_extensionality] *) (* FILL IN HERE *) Admitted. (** [] *)
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * 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. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // 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 REGENTS OF THE // UNIVERSITY OF CALIFORNIA 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. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: rxc_engine_classic.v // Version: 1.0 // Verilog Standard: Verilog-2001 // Description: The RXC Engine (Ultrascale) takes a single stream of // AXI packets and provides the completion packets on the RXC Interface. // This Engine is capable of operating at "line rate". // Author: Dustin Richmond (@darichmond) //----------------------------------------------------------------------------- `timescale 1ns/1ns `include "trellis.vh" `include "ultrascale.vh" module rxc_engine_ultrascale #(parameter C_PCI_DATA_WIDTH = 128, parameter C_RX_PIPELINE_DEPTH=10, // Number of data pipeline registers for metadata and data stages parameter C_RX_META_STAGES = 0, parameter C_RX_DATA_STAGES = 1) (// Interface: Clocks input CLK, // Interface: Resets input RST_BUS, // Replacement for generic RST_IN input RST_LOGIC, // Addition for RIFFA_RST output DONE_RXC_RST, // Interface: RC input M_AXIS_RC_TVALID, input M_AXIS_RC_TLAST, input [C_PCI_DATA_WIDTH-1:0] M_AXIS_RC_TDATA, input [(C_PCI_DATA_WIDTH/32)-1:0] M_AXIS_RC_TKEEP, input [`SIG_RC_TUSER_W-1:0] M_AXIS_RC_TUSER, output M_AXIS_RC_TREADY, // Interface: RXC Engine output [C_PCI_DATA_WIDTH-1:0] RXC_DATA, output RXC_DATA_VALID, output [(C_PCI_DATA_WIDTH/32)-1:0] RXC_DATA_WORD_ENABLE, output RXC_DATA_START_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] RXC_DATA_START_OFFSET, output RXC_DATA_END_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] RXC_DATA_END_OFFSET, output [`SIG_LBE_W-1:0] RXC_META_LDWBE, output [`SIG_FBE_W-1:0] RXC_META_FDWBE, output [`SIG_TAG_W-1:0] RXC_META_TAG, output [`SIG_LOWADDR_W-1:0] RXC_META_ADDR, output [`SIG_TYPE_W-1:0] RXC_META_TYPE, output [`SIG_LEN_W-1:0] RXC_META_LENGTH, output [`SIG_BYTECNT_W-1:0] RXC_META_BYTES_REMAINING, output [`SIG_CPLID_W-1:0] RXC_META_COMPLETER_ID, output RXC_META_EP ); // Width of the Byte Enable Shift register localparam C_RX_BE_W = (`SIG_FBE_W + `SIG_LBE_W); localparam C_RX_INPUT_STAGES = 0; localparam C_RX_OUTPUT_STAGES = 2; // Should always be at least one localparam C_RX_COMPUTATION_STAGES = 1; localparam C_TOTAL_STAGES = C_RX_COMPUTATION_STAGES + C_RX_OUTPUT_STAGES + C_RX_INPUT_STAGES; // CYCLE = LOW ORDER BIT (INDEX) / C_PCI_DATA_WIDTH localparam C_RX_METADW0_CYCLE = (`UPKT_RXC_METADW0_I/C_PCI_DATA_WIDTH) + C_RX_INPUT_STAGES; localparam C_RX_METADW1_CYCLE = (`UPKT_RXC_METADW1_I/C_PCI_DATA_WIDTH) + C_RX_INPUT_STAGES; localparam C_RX_METADW2_CYCLE = (`UPKT_RXC_METADW2_I/C_PCI_DATA_WIDTH) + C_RX_INPUT_STAGES; localparam C_RX_PAYLOAD_CYCLE = (`UPKT_RXC_PAYLOAD_I/C_PCI_DATA_WIDTH) + C_RX_INPUT_STAGES; localparam C_RX_BE_CYCLE = C_RX_INPUT_STAGES; // Available on the first cycle (as per the spec) localparam C_RX_METADW0_INDEX = C_PCI_DATA_WIDTH*C_RX_INPUT_STAGES + (`UPKT_RXC_METADW0_I%C_PCI_DATA_WIDTH); localparam C_RX_METADW1_INDEX = C_PCI_DATA_WIDTH*C_RX_INPUT_STAGES + (`UPKT_RXC_METADW1_I%C_PCI_DATA_WIDTH); localparam C_RX_METADW2_INDEX = C_PCI_DATA_WIDTH*C_RX_INPUT_STAGES + (`UPKT_RXC_METADW2_I%C_PCI_DATA_WIDTH); localparam C_RX_BE_INDEX = C_PCI_DATA_WIDTH*C_RX_INPUT_STAGES; // Mask width of the calculated SOF/EOF fields localparam C_OFFSET_WIDTH = clog2(C_PCI_DATA_WIDTH/32); wire wMAxisRcSop; wire wMAxisRcTlast; wire [C_RX_PIPELINE_DEPTH:0] wRxSrSop; wire [C_RX_PIPELINE_DEPTH:0] wRxSrEop; wire [C_RX_PIPELINE_DEPTH:0] wRxSrDataValid; wire [(C_RX_PIPELINE_DEPTH+1)*C_RX_BE_W-1:0] wRxSrBe; wire [(C_RX_PIPELINE_DEPTH+1)*C_PCI_DATA_WIDTH-1:0] wRxSrData; wire wRxcDataValid; wire wRxcDataReady; // Pinned High wire [(C_PCI_DATA_WIDTH/32)-1:0] wRxcDataWordEnable; wire wRxcDataEndFlag; wire [clog2(C_PCI_DATA_WIDTH/32)-1:0] wRxcDataEndOffset; wire wRxcDataStartFlag; wire [clog2(C_PCI_DATA_WIDTH/32)-1:0] wRxcDataStartOffset; wire [`SIG_BYTECNT_W-1:0] wRxcMetaBytesRemaining; wire [`SIG_CPLID_W-1:0] wRxcMetaCompleterId; wire [`UPKT_RXC_MAXHDR_W-1:0] wRxcHdr; wire [`SIG_TYPE_W-1:0] wRxcType; wire [`SIG_BARDECODE_W-1:0] wRxcBarDecoded; wire [`UPKT_RXC_MAXHDR_W-1:0] wHdr; wire [`SIG_TYPE_W-1:0] wType; wire wHasPayload; wire _wEndFlag; wire wEndFlag; wire wEndFlagLastCycle; wire [clog2(C_PCI_DATA_WIDTH/32)-1:0] wEndOffset; wire [(C_PCI_DATA_WIDTH/32)-1:0] wEndMask; wire _wStartFlag; wire wStartFlag; wire [1:0] wStartFlags; wire [clog2(C_PCI_DATA_WIDTH/32)-1:0] wStartOffset; wire [(C_PCI_DATA_WIDTH/32)-1:0] wStartMask; wire [C_OFFSET_WIDTH-1:0] wOffsetMask; reg rValid,_rValid; reg rRST; assign DONE_RXC_RST = ~rRST; assign wMAxisRcSop = M_AXIS_RC_TUSER[`UPKT_RC_TUSER_SOP_I]; assign wMAxisRcTlast = M_AXIS_RC_TLAST; // We assert the end flag on the last cycle of a packet, however on single // cycle packets we need to check that there wasn't an end flag last cycle // (because wStartFlag will take priority when setting rValid) so we can // deassert rValid if necessary. assign wEndFlag = wRxSrEop[C_RX_INPUT_STAGES + C_RX_COMPUTATION_STAGES]; assign wEndFlagLastCycle = wRxSrEop[C_RX_INPUT_STAGES + C_RX_COMPUTATION_STAGES + 1]; /* verilator lint_off WIDTH */ assign wStartOffset = 3; assign wEndOffset = wHdr[`UPKT_RXC_LENGTH_I +: C_OFFSET_WIDTH] + ((`UPKT_RXC_MAXHDR_W-32)/32); /* verilator lint_on WIDTH */ // Output assignments. See the header file derived from the user // guide for indices. assign RXC_META_LENGTH = wRxcHdr[`UPKT_RXC_LENGTH_I+:`SIG_LEN_W]; //assign RXC_META_ATTR = wRxcHdr[`UPKT_RXC_ATTR_R]; //assign RXC_META_TC = wRxcHdr[`UPKT_RXC_TC_R]; assign RXC_META_TAG = wRxcHdr[`UPKT_RXC_TAG_R]; assign RXC_META_FDWBE = 0;// TODO: Remove (use addr) assign RXC_META_LDWBE = 0;// TODO: Remove (use addr) assign RXC_META_ADDR = wRxcHdr[(`UPKT_RXC_ADDRLOW_I) +: `SIG_LOWADDR_W]; assign RXC_DATA_START_FLAG = wRxcDataStartFlag; assign RXC_DATA_START_OFFSET = {C_PCI_DATA_WIDTH > 64, 1'b1}; assign RXC_DATA_END_FLAG = wRxcDataEndFlag; assign RXC_DATA_END_OFFSET = wRxcDataEndOffset; assign RXC_DATA_VALID = wRxcDataValid; assign RXC_DATA = wRxSrData[(C_TOTAL_STAGES)*C_PCI_DATA_WIDTH +: C_PCI_DATA_WIDTH]; assign RXC_META_TYPE = wRxcType; assign RXC_META_BYTES_REMAINING = wRxcHdr[`UPKT_RXC_BYTECNT_I +: `SIG_BYTECNT_W]; assign RXC_META_COMPLETER_ID = wRxcHdr[`UPKT_RXC_CPLID_R]; assign RXC_META_EP = wRxcHdr[`UPKT_RXC_EP_R]; assign M_AXIS_RC_TREADY = 1'b1; assign _wEndFlag = wRxSrEop[C_RX_INPUT_STAGES]; assign wEndFlag = wRxSrEop[C_RX_INPUT_STAGES+1]; assign _wStartFlag = wStartFlags != 0; assign wType = (wHasPayload)? `TRLS_CPL_WD: `TRLS_CPL_ND; generate if(C_PCI_DATA_WIDTH == 64) begin assign wStartFlags[0] = 0; assign wStartFlags[1] = wRxSrSop[C_RX_INPUT_STAGES + 1]; //assign wStartFlags[0] = wRxSrSop[C_RX_INPUT_STAGES + 1] & wRxSrEop[C_RX_INPUT_STAGES]; // No Payload end else if (C_PCI_DATA_WIDTH == 128) begin assign wStartFlags[1] = 0; assign wStartFlags[0] = wRxSrSop[C_RX_INPUT_STAGES]; end else begin // 256 assign wStartFlags[1] = 0; assign wStartFlags[0] = wRxSrSop[C_RX_INPUT_STAGES]; end // else: !if(C_PCI_DATA_WIDTH == 128) endgenerate always @(*) begin _rValid = rValid; if(_wStartFlag) begin _rValid = 1'b1; end else if (wEndFlag) begin _rValid = 1'b0; end end always @(posedge CLK) begin if(rRST) begin rValid <= 1'b0; end else begin rValid <= _rValid; end end always @(posedge CLK) begin rRST <= RST_BUS | RST_LOGIC; end register #(// Parameters .C_WIDTH (1), .C_VALUE (0) /*AUTOINSTPARAM*/) start_flag_register (// Outputs .RD_DATA (wStartFlag), // Inputs .WR_DATA (_wStartFlag), .WR_EN (1), .RST_IN (0), /*AUTOINST*/ // Inputs .CLK (CLK)); register #(// Parameters .C_WIDTH (32), .C_VALUE (0) /*AUTOINSTPARAM*/) meta_DW2_register (// Outputs .RD_DATA (wHdr[95:64]), // Inputs .WR_DATA (wRxSrData[C_RX_METADW2_INDEX +: 32]), .WR_EN (wRxSrSop[C_RX_METADW2_CYCLE]), .RST_IN (0), /*AUTOINST*/ // Inputs .CLK (CLK)); register #(// Parameters .C_WIDTH (32 + 1), .C_VALUE (0) /*AUTOINSTPARAM*/) meta_DW1_register (// Outputs .RD_DATA ({wHdr[63:32],wHasPayload}), // Inputs .WR_DATA ({wRxSrData[C_RX_METADW1_INDEX +: 32], wRxSrData[C_RX_METADW1_INDEX +: `UPKT_LEN_W] != 0}), .WR_EN (wRxSrSop[C_RX_METADW1_CYCLE]), .RST_IN (0), /*AUTOINST*/ // Inputs .CLK (CLK)); register #(// Parameters .C_WIDTH (32), .C_VALUE (0) /*AUTOINSTPARAM*/) metadata_DW0_register (// Outputs .RD_DATA (wHdr[31:0]), // Inputs .WR_DATA (wRxSrData[C_RX_METADW0_INDEX +: 32]), .WR_EN (wRxSrSop[C_RX_METADW0_CYCLE]), .RST_IN (0), /*AUTOINST*/ // Inputs .CLK (CLK)); // Shift register for input data with output taps for each delayed // cycle. shiftreg #(// Parameters .C_DEPTH (C_RX_PIPELINE_DEPTH), .C_WIDTH (C_PCI_DATA_WIDTH), .C_VALUE (0) /*AUTOINSTPARAM*/) data_shiftreg_inst (// Outputs .RD_DATA (wRxSrData), // Inputs .WR_DATA (M_AXIS_RC_TDATA), .RST_IN (0), /*AUTOINST*/ // Inputs .CLK (CLK)); // Start Flag Shift Register. Data enables are derived from the // taps on this shift register. shiftreg #(// Parameters .C_DEPTH (C_RX_PIPELINE_DEPTH), .C_WIDTH (1'b1), .C_VALUE (0) /*AUTOINSTPARAM*/) sop_shiftreg_inst (// Outputs .RD_DATA (wRxSrSop), // Inputs .WR_DATA (wMAxisRcSop & M_AXIS_RC_TVALID), .RST_IN (0), /*AUTOINST*/ // Inputs .CLK (CLK)); // End Flag Shift Register. shiftreg #(// Parameters .C_DEPTH (C_RX_PIPELINE_DEPTH), .C_WIDTH (1'b1), .C_VALUE (0) /*AUTOINSTPARAM*/) eop_shiftreg_inst (// Outputs .RD_DATA (wRxSrEop), // Inputs .WR_DATA (wMAxisRcTlast), .RST_IN (0), /*AUTOINST*/ // Inputs .CLK (CLK)); // Data Valid Shift Register. Data enables are derived from the // taps on this shift register. shiftreg #(// Parameters .C_DEPTH (C_RX_PIPELINE_DEPTH), .C_WIDTH (1), .C_VALUE (0) /*AUTOINSTPARAM*/) valid_shiftreg_inst (// Outputs .RD_DATA (wRxSrDataValid), // Inputs .WR_DATA (M_AXIS_RC_TVALID), .RST_IN (rRST), /*AUTOINST*/ // Inputs .CLK (CLK)); assign wStartMask = {C_PCI_DATA_WIDTH/32{1'b1}} << ({C_OFFSET_WIDTH{wStartFlag}}& wStartOffset[C_OFFSET_WIDTH-1:0]); offset_to_mask #(// Parameters .C_MASK_SWAP (0), .C_MASK_WIDTH (C_PCI_DATA_WIDTH/32) /*AUTOINSTPARAM*/) o2m_ef (// Outputs .MASK (wEndMask), // Inputs .OFFSET_ENABLE (wEndFlag), .OFFSET (wEndOffset) /*AUTOINST*/); generate if(C_RX_OUTPUT_STAGES == 0) begin assign RXC_DATA_WORD_ENABLE = {wEndMask & wStartMask} & {C_PCI_DATA_WIDTH/32{~rValid | ~wHasPayload}}; end else begin register #(// Parameters .C_WIDTH (C_PCI_DATA_WIDTH/32), .C_VALUE (0) /*AUTOINSTPARAM*/) dw_enable (// Outputs .RD_DATA (wRxcDataWordEnable), // Inputs .RST_IN (~rValid | ~wHasPayload), .WR_DATA (wEndMask & wStartMask), .WR_EN (1), /*AUTOINST*/ // Inputs .CLK (CLK)); pipeline #( // Parameters .C_DEPTH (C_RX_OUTPUT_STAGES-1), .C_WIDTH (C_PCI_DATA_WIDTH/32), .C_USE_MEMORY (0) /*AUTOINSTPARAM*/) dw_pipeline (// Outputs .WR_DATA_READY (), // Pinned to 1 .RD_DATA (RXC_DATA_WORD_ENABLE), .RD_DATA_VALID (), // Inputs .WR_DATA (wRxcDataWordEnable), .WR_DATA_VALID (1), .RD_DATA_READY (1'b1), .RST_IN (0), /*AUTOINST*/ // Inputs .CLK (CLK)); end endgenerate // Shift register for input data with output taps for each delayed // cycle. pipeline #( // Parameters .C_DEPTH (C_RX_OUTPUT_STAGES), .C_WIDTH (`UPKT_RXC_MAXHDR_W + 2*(1 + clog2(C_PCI_DATA_WIDTH/32))+`SIG_TYPE_W), .C_USE_MEMORY (0) /*AUTOINSTPARAM*/) output_pipeline ( // Outputs .WR_DATA_READY (), // Pinned to 1 .RD_DATA ({wRxcHdr, wRxcDataStartFlag, wRxcDataStartOffset,wRxcDataEndFlag, wRxcDataEndOffset,wRxcType}), .RD_DATA_VALID (wRxcDataValid), // Inputs .WR_DATA ({wHdr,wStartFlag, wStartOffset[C_OFFSET_WIDTH-1:0], wEndFlag,wEndOffset[C_OFFSET_WIDTH-1:0],wType}), .WR_DATA_VALID (rValid), .RD_DATA_READY (1'b1), .RST_IN (rRST), /*AUTOINST*/ // Inputs .CLK (CLK)); endmodule // Local Variables: // verilog-library-directories:("." "../../../common/") // End:
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * 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. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // 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 REGENTS OF THE // UNIVERSITY OF CALIFORNIA 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. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: rxc_engine_classic.v // Version: 1.0 // Verilog Standard: Verilog-2001 // Description: The RXC Engine (Ultrascale) takes a single stream of // AXI packets and provides the completion packets on the RXC Interface. // This Engine is capable of operating at "line rate". // Author: Dustin Richmond (@darichmond) //----------------------------------------------------------------------------- `timescale 1ns/1ns `include "trellis.vh" `include "ultrascale.vh" module rxc_engine_ultrascale #(parameter C_PCI_DATA_WIDTH = 128, parameter C_RX_PIPELINE_DEPTH=10, // Number of data pipeline registers for metadata and data stages parameter C_RX_META_STAGES = 0, parameter C_RX_DATA_STAGES = 1) (// Interface: Clocks input CLK, // Interface: Resets input RST_BUS, // Replacement for generic RST_IN input RST_LOGIC, // Addition for RIFFA_RST output DONE_RXC_RST, // Interface: RC input M_AXIS_RC_TVALID, input M_AXIS_RC_TLAST, input [C_PCI_DATA_WIDTH-1:0] M_AXIS_RC_TDATA, input [(C_PCI_DATA_WIDTH/32)-1:0] M_AXIS_RC_TKEEP, input [`SIG_RC_TUSER_W-1:0] M_AXIS_RC_TUSER, output M_AXIS_RC_TREADY, // Interface: RXC Engine output [C_PCI_DATA_WIDTH-1:0] RXC_DATA, output RXC_DATA_VALID, output [(C_PCI_DATA_WIDTH/32)-1:0] RXC_DATA_WORD_ENABLE, output RXC_DATA_START_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] RXC_DATA_START_OFFSET, output RXC_DATA_END_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] RXC_DATA_END_OFFSET, output [`SIG_LBE_W-1:0] RXC_META_LDWBE, output [`SIG_FBE_W-1:0] RXC_META_FDWBE, output [`SIG_TAG_W-1:0] RXC_META_TAG, output [`SIG_LOWADDR_W-1:0] RXC_META_ADDR, output [`SIG_TYPE_W-1:0] RXC_META_TYPE, output [`SIG_LEN_W-1:0] RXC_META_LENGTH, output [`SIG_BYTECNT_W-1:0] RXC_META_BYTES_REMAINING, output [`SIG_CPLID_W-1:0] RXC_META_COMPLETER_ID, output RXC_META_EP ); // Width of the Byte Enable Shift register localparam C_RX_BE_W = (`SIG_FBE_W + `SIG_LBE_W); localparam C_RX_INPUT_STAGES = 0; localparam C_RX_OUTPUT_STAGES = 2; // Should always be at least one localparam C_RX_COMPUTATION_STAGES = 1; localparam C_TOTAL_STAGES = C_RX_COMPUTATION_STAGES + C_RX_OUTPUT_STAGES + C_RX_INPUT_STAGES; // CYCLE = LOW ORDER BIT (INDEX) / C_PCI_DATA_WIDTH localparam C_RX_METADW0_CYCLE = (`UPKT_RXC_METADW0_I/C_PCI_DATA_WIDTH) + C_RX_INPUT_STAGES; localparam C_RX_METADW1_CYCLE = (`UPKT_RXC_METADW1_I/C_PCI_DATA_WIDTH) + C_RX_INPUT_STAGES; localparam C_RX_METADW2_CYCLE = (`UPKT_RXC_METADW2_I/C_PCI_DATA_WIDTH) + C_RX_INPUT_STAGES; localparam C_RX_PAYLOAD_CYCLE = (`UPKT_RXC_PAYLOAD_I/C_PCI_DATA_WIDTH) + C_RX_INPUT_STAGES; localparam C_RX_BE_CYCLE = C_RX_INPUT_STAGES; // Available on the first cycle (as per the spec) localparam C_RX_METADW0_INDEX = C_PCI_DATA_WIDTH*C_RX_INPUT_STAGES + (`UPKT_RXC_METADW0_I%C_PCI_DATA_WIDTH); localparam C_RX_METADW1_INDEX = C_PCI_DATA_WIDTH*C_RX_INPUT_STAGES + (`UPKT_RXC_METADW1_I%C_PCI_DATA_WIDTH); localparam C_RX_METADW2_INDEX = C_PCI_DATA_WIDTH*C_RX_INPUT_STAGES + (`UPKT_RXC_METADW2_I%C_PCI_DATA_WIDTH); localparam C_RX_BE_INDEX = C_PCI_DATA_WIDTH*C_RX_INPUT_STAGES; // Mask width of the calculated SOF/EOF fields localparam C_OFFSET_WIDTH = clog2(C_PCI_DATA_WIDTH/32); wire wMAxisRcSop; wire wMAxisRcTlast; wire [C_RX_PIPELINE_DEPTH:0] wRxSrSop; wire [C_RX_PIPELINE_DEPTH:0] wRxSrEop; wire [C_RX_PIPELINE_DEPTH:0] wRxSrDataValid; wire [(C_RX_PIPELINE_DEPTH+1)*C_RX_BE_W-1:0] wRxSrBe; wire [(C_RX_PIPELINE_DEPTH+1)*C_PCI_DATA_WIDTH-1:0] wRxSrData; wire wRxcDataValid; wire wRxcDataReady; // Pinned High wire [(C_PCI_DATA_WIDTH/32)-1:0] wRxcDataWordEnable; wire wRxcDataEndFlag; wire [clog2(C_PCI_DATA_WIDTH/32)-1:0] wRxcDataEndOffset; wire wRxcDataStartFlag; wire [clog2(C_PCI_DATA_WIDTH/32)-1:0] wRxcDataStartOffset; wire [`SIG_BYTECNT_W-1:0] wRxcMetaBytesRemaining; wire [`SIG_CPLID_W-1:0] wRxcMetaCompleterId; wire [`UPKT_RXC_MAXHDR_W-1:0] wRxcHdr; wire [`SIG_TYPE_W-1:0] wRxcType; wire [`SIG_BARDECODE_W-1:0] wRxcBarDecoded; wire [`UPKT_RXC_MAXHDR_W-1:0] wHdr; wire [`SIG_TYPE_W-1:0] wType; wire wHasPayload; wire _wEndFlag; wire wEndFlag; wire wEndFlagLastCycle; wire [clog2(C_PCI_DATA_WIDTH/32)-1:0] wEndOffset; wire [(C_PCI_DATA_WIDTH/32)-1:0] wEndMask; wire _wStartFlag; wire wStartFlag; wire [1:0] wStartFlags; wire [clog2(C_PCI_DATA_WIDTH/32)-1:0] wStartOffset; wire [(C_PCI_DATA_WIDTH/32)-1:0] wStartMask; wire [C_OFFSET_WIDTH-1:0] wOffsetMask; reg rValid,_rValid; reg rRST; assign DONE_RXC_RST = ~rRST; assign wMAxisRcSop = M_AXIS_RC_TUSER[`UPKT_RC_TUSER_SOP_I]; assign wMAxisRcTlast = M_AXIS_RC_TLAST; // We assert the end flag on the last cycle of a packet, however on single // cycle packets we need to check that there wasn't an end flag last cycle // (because wStartFlag will take priority when setting rValid) so we can // deassert rValid if necessary. assign wEndFlag = wRxSrEop[C_RX_INPUT_STAGES + C_RX_COMPUTATION_STAGES]; assign wEndFlagLastCycle = wRxSrEop[C_RX_INPUT_STAGES + C_RX_COMPUTATION_STAGES + 1]; /* verilator lint_off WIDTH */ assign wStartOffset = 3; assign wEndOffset = wHdr[`UPKT_RXC_LENGTH_I +: C_OFFSET_WIDTH] + ((`UPKT_RXC_MAXHDR_W-32)/32); /* verilator lint_on WIDTH */ // Output assignments. See the header file derived from the user // guide for indices. assign RXC_META_LENGTH = wRxcHdr[`UPKT_RXC_LENGTH_I+:`SIG_LEN_W]; //assign RXC_META_ATTR = wRxcHdr[`UPKT_RXC_ATTR_R]; //assign RXC_META_TC = wRxcHdr[`UPKT_RXC_TC_R]; assign RXC_META_TAG = wRxcHdr[`UPKT_RXC_TAG_R]; assign RXC_META_FDWBE = 0;// TODO: Remove (use addr) assign RXC_META_LDWBE = 0;// TODO: Remove (use addr) assign RXC_META_ADDR = wRxcHdr[(`UPKT_RXC_ADDRLOW_I) +: `SIG_LOWADDR_W]; assign RXC_DATA_START_FLAG = wRxcDataStartFlag; assign RXC_DATA_START_OFFSET = {C_PCI_DATA_WIDTH > 64, 1'b1}; assign RXC_DATA_END_FLAG = wRxcDataEndFlag; assign RXC_DATA_END_OFFSET = wRxcDataEndOffset; assign RXC_DATA_VALID = wRxcDataValid; assign RXC_DATA = wRxSrData[(C_TOTAL_STAGES)*C_PCI_DATA_WIDTH +: C_PCI_DATA_WIDTH]; assign RXC_META_TYPE = wRxcType; assign RXC_META_BYTES_REMAINING = wRxcHdr[`UPKT_RXC_BYTECNT_I +: `SIG_BYTECNT_W]; assign RXC_META_COMPLETER_ID = wRxcHdr[`UPKT_RXC_CPLID_R]; assign RXC_META_EP = wRxcHdr[`UPKT_RXC_EP_R]; assign M_AXIS_RC_TREADY = 1'b1; assign _wEndFlag = wRxSrEop[C_RX_INPUT_STAGES]; assign wEndFlag = wRxSrEop[C_RX_INPUT_STAGES+1]; assign _wStartFlag = wStartFlags != 0; assign wType = (wHasPayload)? `TRLS_CPL_WD: `TRLS_CPL_ND; generate if(C_PCI_DATA_WIDTH == 64) begin assign wStartFlags[0] = 0; assign wStartFlags[1] = wRxSrSop[C_RX_INPUT_STAGES + 1]; //assign wStartFlags[0] = wRxSrSop[C_RX_INPUT_STAGES + 1] & wRxSrEop[C_RX_INPUT_STAGES]; // No Payload end else if (C_PCI_DATA_WIDTH == 128) begin assign wStartFlags[1] = 0; assign wStartFlags[0] = wRxSrSop[C_RX_INPUT_STAGES]; end else begin // 256 assign wStartFlags[1] = 0; assign wStartFlags[0] = wRxSrSop[C_RX_INPUT_STAGES]; end // else: !if(C_PCI_DATA_WIDTH == 128) endgenerate always @(*) begin _rValid = rValid; if(_wStartFlag) begin _rValid = 1'b1; end else if (wEndFlag) begin _rValid = 1'b0; end end always @(posedge CLK) begin if(rRST) begin rValid <= 1'b0; end else begin rValid <= _rValid; end end always @(posedge CLK) begin rRST <= RST_BUS | RST_LOGIC; end register #(// Parameters .C_WIDTH (1), .C_VALUE (0) /*AUTOINSTPARAM*/) start_flag_register (// Outputs .RD_DATA (wStartFlag), // Inputs .WR_DATA (_wStartFlag), .WR_EN (1), .RST_IN (0), /*AUTOINST*/ // Inputs .CLK (CLK)); register #(// Parameters .C_WIDTH (32), .C_VALUE (0) /*AUTOINSTPARAM*/) meta_DW2_register (// Outputs .RD_DATA (wHdr[95:64]), // Inputs .WR_DATA (wRxSrData[C_RX_METADW2_INDEX +: 32]), .WR_EN (wRxSrSop[C_RX_METADW2_CYCLE]), .RST_IN (0), /*AUTOINST*/ // Inputs .CLK (CLK)); register #(// Parameters .C_WIDTH (32 + 1), .C_VALUE (0) /*AUTOINSTPARAM*/) meta_DW1_register (// Outputs .RD_DATA ({wHdr[63:32],wHasPayload}), // Inputs .WR_DATA ({wRxSrData[C_RX_METADW1_INDEX +: 32], wRxSrData[C_RX_METADW1_INDEX +: `UPKT_LEN_W] != 0}), .WR_EN (wRxSrSop[C_RX_METADW1_CYCLE]), .RST_IN (0), /*AUTOINST*/ // Inputs .CLK (CLK)); register #(// Parameters .C_WIDTH (32), .C_VALUE (0) /*AUTOINSTPARAM*/) metadata_DW0_register (// Outputs .RD_DATA (wHdr[31:0]), // Inputs .WR_DATA (wRxSrData[C_RX_METADW0_INDEX +: 32]), .WR_EN (wRxSrSop[C_RX_METADW0_CYCLE]), .RST_IN (0), /*AUTOINST*/ // Inputs .CLK (CLK)); // Shift register for input data with output taps for each delayed // cycle. shiftreg #(// Parameters .C_DEPTH (C_RX_PIPELINE_DEPTH), .C_WIDTH (C_PCI_DATA_WIDTH), .C_VALUE (0) /*AUTOINSTPARAM*/) data_shiftreg_inst (// Outputs .RD_DATA (wRxSrData), // Inputs .WR_DATA (M_AXIS_RC_TDATA), .RST_IN (0), /*AUTOINST*/ // Inputs .CLK (CLK)); // Start Flag Shift Register. Data enables are derived from the // taps on this shift register. shiftreg #(// Parameters .C_DEPTH (C_RX_PIPELINE_DEPTH), .C_WIDTH (1'b1), .C_VALUE (0) /*AUTOINSTPARAM*/) sop_shiftreg_inst (// Outputs .RD_DATA (wRxSrSop), // Inputs .WR_DATA (wMAxisRcSop & M_AXIS_RC_TVALID), .RST_IN (0), /*AUTOINST*/ // Inputs .CLK (CLK)); // End Flag Shift Register. shiftreg #(// Parameters .C_DEPTH (C_RX_PIPELINE_DEPTH), .C_WIDTH (1'b1), .C_VALUE (0) /*AUTOINSTPARAM*/) eop_shiftreg_inst (// Outputs .RD_DATA (wRxSrEop), // Inputs .WR_DATA (wMAxisRcTlast), .RST_IN (0), /*AUTOINST*/ // Inputs .CLK (CLK)); // Data Valid Shift Register. Data enables are derived from the // taps on this shift register. shiftreg #(// Parameters .C_DEPTH (C_RX_PIPELINE_DEPTH), .C_WIDTH (1), .C_VALUE (0) /*AUTOINSTPARAM*/) valid_shiftreg_inst (// Outputs .RD_DATA (wRxSrDataValid), // Inputs .WR_DATA (M_AXIS_RC_TVALID), .RST_IN (rRST), /*AUTOINST*/ // Inputs .CLK (CLK)); assign wStartMask = {C_PCI_DATA_WIDTH/32{1'b1}} << ({C_OFFSET_WIDTH{wStartFlag}}& wStartOffset[C_OFFSET_WIDTH-1:0]); offset_to_mask #(// Parameters .C_MASK_SWAP (0), .C_MASK_WIDTH (C_PCI_DATA_WIDTH/32) /*AUTOINSTPARAM*/) o2m_ef (// Outputs .MASK (wEndMask), // Inputs .OFFSET_ENABLE (wEndFlag), .OFFSET (wEndOffset) /*AUTOINST*/); generate if(C_RX_OUTPUT_STAGES == 0) begin assign RXC_DATA_WORD_ENABLE = {wEndMask & wStartMask} & {C_PCI_DATA_WIDTH/32{~rValid | ~wHasPayload}}; end else begin register #(// Parameters .C_WIDTH (C_PCI_DATA_WIDTH/32), .C_VALUE (0) /*AUTOINSTPARAM*/) dw_enable (// Outputs .RD_DATA (wRxcDataWordEnable), // Inputs .RST_IN (~rValid | ~wHasPayload), .WR_DATA (wEndMask & wStartMask), .WR_EN (1), /*AUTOINST*/ // Inputs .CLK (CLK)); pipeline #( // Parameters .C_DEPTH (C_RX_OUTPUT_STAGES-1), .C_WIDTH (C_PCI_DATA_WIDTH/32), .C_USE_MEMORY (0) /*AUTOINSTPARAM*/) dw_pipeline (// Outputs .WR_DATA_READY (), // Pinned to 1 .RD_DATA (RXC_DATA_WORD_ENABLE), .RD_DATA_VALID (), // Inputs .WR_DATA (wRxcDataWordEnable), .WR_DATA_VALID (1), .RD_DATA_READY (1'b1), .RST_IN (0), /*AUTOINST*/ // Inputs .CLK (CLK)); end endgenerate // Shift register for input data with output taps for each delayed // cycle. pipeline #( // Parameters .C_DEPTH (C_RX_OUTPUT_STAGES), .C_WIDTH (`UPKT_RXC_MAXHDR_W + 2*(1 + clog2(C_PCI_DATA_WIDTH/32))+`SIG_TYPE_W), .C_USE_MEMORY (0) /*AUTOINSTPARAM*/) output_pipeline ( // Outputs .WR_DATA_READY (), // Pinned to 1 .RD_DATA ({wRxcHdr, wRxcDataStartFlag, wRxcDataStartOffset,wRxcDataEndFlag, wRxcDataEndOffset,wRxcType}), .RD_DATA_VALID (wRxcDataValid), // Inputs .WR_DATA ({wHdr,wStartFlag, wStartOffset[C_OFFSET_WIDTH-1:0], wEndFlag,wEndOffset[C_OFFSET_WIDTH-1:0],wType}), .WR_DATA_VALID (rValid), .RD_DATA_READY (1'b1), .RST_IN (rRST), /*AUTOINST*/ // Inputs .CLK (CLK)); endmodule // Local Variables: // verilog-library-directories:("." "../../../common/") // End:
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * 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. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // 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 REGENTS OF THE // UNIVERSITY OF CALIFORNIA 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. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: rxc_engine_classic.v // Version: 1.0 // Verilog Standard: Verilog-2001 // Description: The RXC Engine (Ultrascale) takes a single stream of // AXI packets and provides the completion packets on the RXC Interface. // This Engine is capable of operating at "line rate". // Author: Dustin Richmond (@darichmond) //----------------------------------------------------------------------------- `timescale 1ns/1ns `include "trellis.vh" `include "ultrascale.vh" module rxc_engine_ultrascale #(parameter C_PCI_DATA_WIDTH = 128, parameter C_RX_PIPELINE_DEPTH=10, // Number of data pipeline registers for metadata and data stages parameter C_RX_META_STAGES = 0, parameter C_RX_DATA_STAGES = 1) (// Interface: Clocks input CLK, // Interface: Resets input RST_BUS, // Replacement for generic RST_IN input RST_LOGIC, // Addition for RIFFA_RST output DONE_RXC_RST, // Interface: RC input M_AXIS_RC_TVALID, input M_AXIS_RC_TLAST, input [C_PCI_DATA_WIDTH-1:0] M_AXIS_RC_TDATA, input [(C_PCI_DATA_WIDTH/32)-1:0] M_AXIS_RC_TKEEP, input [`SIG_RC_TUSER_W-1:0] M_AXIS_RC_TUSER, output M_AXIS_RC_TREADY, // Interface: RXC Engine output [C_PCI_DATA_WIDTH-1:0] RXC_DATA, output RXC_DATA_VALID, output [(C_PCI_DATA_WIDTH/32)-1:0] RXC_DATA_WORD_ENABLE, output RXC_DATA_START_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] RXC_DATA_START_OFFSET, output RXC_DATA_END_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] RXC_DATA_END_OFFSET, output [`SIG_LBE_W-1:0] RXC_META_LDWBE, output [`SIG_FBE_W-1:0] RXC_META_FDWBE, output [`SIG_TAG_W-1:0] RXC_META_TAG, output [`SIG_LOWADDR_W-1:0] RXC_META_ADDR, output [`SIG_TYPE_W-1:0] RXC_META_TYPE, output [`SIG_LEN_W-1:0] RXC_META_LENGTH, output [`SIG_BYTECNT_W-1:0] RXC_META_BYTES_REMAINING, output [`SIG_CPLID_W-1:0] RXC_META_COMPLETER_ID, output RXC_META_EP ); // Width of the Byte Enable Shift register localparam C_RX_BE_W = (`SIG_FBE_W + `SIG_LBE_W); localparam C_RX_INPUT_STAGES = 0; localparam C_RX_OUTPUT_STAGES = 2; // Should always be at least one localparam C_RX_COMPUTATION_STAGES = 1; localparam C_TOTAL_STAGES = C_RX_COMPUTATION_STAGES + C_RX_OUTPUT_STAGES + C_RX_INPUT_STAGES; // CYCLE = LOW ORDER BIT (INDEX) / C_PCI_DATA_WIDTH localparam C_RX_METADW0_CYCLE = (`UPKT_RXC_METADW0_I/C_PCI_DATA_WIDTH) + C_RX_INPUT_STAGES; localparam C_RX_METADW1_CYCLE = (`UPKT_RXC_METADW1_I/C_PCI_DATA_WIDTH) + C_RX_INPUT_STAGES; localparam C_RX_METADW2_CYCLE = (`UPKT_RXC_METADW2_I/C_PCI_DATA_WIDTH) + C_RX_INPUT_STAGES; localparam C_RX_PAYLOAD_CYCLE = (`UPKT_RXC_PAYLOAD_I/C_PCI_DATA_WIDTH) + C_RX_INPUT_STAGES; localparam C_RX_BE_CYCLE = C_RX_INPUT_STAGES; // Available on the first cycle (as per the spec) localparam C_RX_METADW0_INDEX = C_PCI_DATA_WIDTH*C_RX_INPUT_STAGES + (`UPKT_RXC_METADW0_I%C_PCI_DATA_WIDTH); localparam C_RX_METADW1_INDEX = C_PCI_DATA_WIDTH*C_RX_INPUT_STAGES + (`UPKT_RXC_METADW1_I%C_PCI_DATA_WIDTH); localparam C_RX_METADW2_INDEX = C_PCI_DATA_WIDTH*C_RX_INPUT_STAGES + (`UPKT_RXC_METADW2_I%C_PCI_DATA_WIDTH); localparam C_RX_BE_INDEX = C_PCI_DATA_WIDTH*C_RX_INPUT_STAGES; // Mask width of the calculated SOF/EOF fields localparam C_OFFSET_WIDTH = clog2(C_PCI_DATA_WIDTH/32); wire wMAxisRcSop; wire wMAxisRcTlast; wire [C_RX_PIPELINE_DEPTH:0] wRxSrSop; wire [C_RX_PIPELINE_DEPTH:0] wRxSrEop; wire [C_RX_PIPELINE_DEPTH:0] wRxSrDataValid; wire [(C_RX_PIPELINE_DEPTH+1)*C_RX_BE_W-1:0] wRxSrBe; wire [(C_RX_PIPELINE_DEPTH+1)*C_PCI_DATA_WIDTH-1:0] wRxSrData; wire wRxcDataValid; wire wRxcDataReady; // Pinned High wire [(C_PCI_DATA_WIDTH/32)-1:0] wRxcDataWordEnable; wire wRxcDataEndFlag; wire [clog2(C_PCI_DATA_WIDTH/32)-1:0] wRxcDataEndOffset; wire wRxcDataStartFlag; wire [clog2(C_PCI_DATA_WIDTH/32)-1:0] wRxcDataStartOffset; wire [`SIG_BYTECNT_W-1:0] wRxcMetaBytesRemaining; wire [`SIG_CPLID_W-1:0] wRxcMetaCompleterId; wire [`UPKT_RXC_MAXHDR_W-1:0] wRxcHdr; wire [`SIG_TYPE_W-1:0] wRxcType; wire [`SIG_BARDECODE_W-1:0] wRxcBarDecoded; wire [`UPKT_RXC_MAXHDR_W-1:0] wHdr; wire [`SIG_TYPE_W-1:0] wType; wire wHasPayload; wire _wEndFlag; wire wEndFlag; wire wEndFlagLastCycle; wire [clog2(C_PCI_DATA_WIDTH/32)-1:0] wEndOffset; wire [(C_PCI_DATA_WIDTH/32)-1:0] wEndMask; wire _wStartFlag; wire wStartFlag; wire [1:0] wStartFlags; wire [clog2(C_PCI_DATA_WIDTH/32)-1:0] wStartOffset; wire [(C_PCI_DATA_WIDTH/32)-1:0] wStartMask; wire [C_OFFSET_WIDTH-1:0] wOffsetMask; reg rValid,_rValid; reg rRST; assign DONE_RXC_RST = ~rRST; assign wMAxisRcSop = M_AXIS_RC_TUSER[`UPKT_RC_TUSER_SOP_I]; assign wMAxisRcTlast = M_AXIS_RC_TLAST; // We assert the end flag on the last cycle of a packet, however on single // cycle packets we need to check that there wasn't an end flag last cycle // (because wStartFlag will take priority when setting rValid) so we can // deassert rValid if necessary. assign wEndFlag = wRxSrEop[C_RX_INPUT_STAGES + C_RX_COMPUTATION_STAGES]; assign wEndFlagLastCycle = wRxSrEop[C_RX_INPUT_STAGES + C_RX_COMPUTATION_STAGES + 1]; /* verilator lint_off WIDTH */ assign wStartOffset = 3; assign wEndOffset = wHdr[`UPKT_RXC_LENGTH_I +: C_OFFSET_WIDTH] + ((`UPKT_RXC_MAXHDR_W-32)/32); /* verilator lint_on WIDTH */ // Output assignments. See the header file derived from the user // guide for indices. assign RXC_META_LENGTH = wRxcHdr[`UPKT_RXC_LENGTH_I+:`SIG_LEN_W]; //assign RXC_META_ATTR = wRxcHdr[`UPKT_RXC_ATTR_R]; //assign RXC_META_TC = wRxcHdr[`UPKT_RXC_TC_R]; assign RXC_META_TAG = wRxcHdr[`UPKT_RXC_TAG_R]; assign RXC_META_FDWBE = 0;// TODO: Remove (use addr) assign RXC_META_LDWBE = 0;// TODO: Remove (use addr) assign RXC_META_ADDR = wRxcHdr[(`UPKT_RXC_ADDRLOW_I) +: `SIG_LOWADDR_W]; assign RXC_DATA_START_FLAG = wRxcDataStartFlag; assign RXC_DATA_START_OFFSET = {C_PCI_DATA_WIDTH > 64, 1'b1}; assign RXC_DATA_END_FLAG = wRxcDataEndFlag; assign RXC_DATA_END_OFFSET = wRxcDataEndOffset; assign RXC_DATA_VALID = wRxcDataValid; assign RXC_DATA = wRxSrData[(C_TOTAL_STAGES)*C_PCI_DATA_WIDTH +: C_PCI_DATA_WIDTH]; assign RXC_META_TYPE = wRxcType; assign RXC_META_BYTES_REMAINING = wRxcHdr[`UPKT_RXC_BYTECNT_I +: `SIG_BYTECNT_W]; assign RXC_META_COMPLETER_ID = wRxcHdr[`UPKT_RXC_CPLID_R]; assign RXC_META_EP = wRxcHdr[`UPKT_RXC_EP_R]; assign M_AXIS_RC_TREADY = 1'b1; assign _wEndFlag = wRxSrEop[C_RX_INPUT_STAGES]; assign wEndFlag = wRxSrEop[C_RX_INPUT_STAGES+1]; assign _wStartFlag = wStartFlags != 0; assign wType = (wHasPayload)? `TRLS_CPL_WD: `TRLS_CPL_ND; generate if(C_PCI_DATA_WIDTH == 64) begin assign wStartFlags[0] = 0; assign wStartFlags[1] = wRxSrSop[C_RX_INPUT_STAGES + 1]; //assign wStartFlags[0] = wRxSrSop[C_RX_INPUT_STAGES + 1] & wRxSrEop[C_RX_INPUT_STAGES]; // No Payload end else if (C_PCI_DATA_WIDTH == 128) begin assign wStartFlags[1] = 0; assign wStartFlags[0] = wRxSrSop[C_RX_INPUT_STAGES]; end else begin // 256 assign wStartFlags[1] = 0; assign wStartFlags[0] = wRxSrSop[C_RX_INPUT_STAGES]; end // else: !if(C_PCI_DATA_WIDTH == 128) endgenerate always @(*) begin _rValid = rValid; if(_wStartFlag) begin _rValid = 1'b1; end else if (wEndFlag) begin _rValid = 1'b0; end end always @(posedge CLK) begin if(rRST) begin rValid <= 1'b0; end else begin rValid <= _rValid; end end always @(posedge CLK) begin rRST <= RST_BUS | RST_LOGIC; end register #(// Parameters .C_WIDTH (1), .C_VALUE (0) /*AUTOINSTPARAM*/) start_flag_register (// Outputs .RD_DATA (wStartFlag), // Inputs .WR_DATA (_wStartFlag), .WR_EN (1), .RST_IN (0), /*AUTOINST*/ // Inputs .CLK (CLK)); register #(// Parameters .C_WIDTH (32), .C_VALUE (0) /*AUTOINSTPARAM*/) meta_DW2_register (// Outputs .RD_DATA (wHdr[95:64]), // Inputs .WR_DATA (wRxSrData[C_RX_METADW2_INDEX +: 32]), .WR_EN (wRxSrSop[C_RX_METADW2_CYCLE]), .RST_IN (0), /*AUTOINST*/ // Inputs .CLK (CLK)); register #(// Parameters .C_WIDTH (32 + 1), .C_VALUE (0) /*AUTOINSTPARAM*/) meta_DW1_register (// Outputs .RD_DATA ({wHdr[63:32],wHasPayload}), // Inputs .WR_DATA ({wRxSrData[C_RX_METADW1_INDEX +: 32], wRxSrData[C_RX_METADW1_INDEX +: `UPKT_LEN_W] != 0}), .WR_EN (wRxSrSop[C_RX_METADW1_CYCLE]), .RST_IN (0), /*AUTOINST*/ // Inputs .CLK (CLK)); register #(// Parameters .C_WIDTH (32), .C_VALUE (0) /*AUTOINSTPARAM*/) metadata_DW0_register (// Outputs .RD_DATA (wHdr[31:0]), // Inputs .WR_DATA (wRxSrData[C_RX_METADW0_INDEX +: 32]), .WR_EN (wRxSrSop[C_RX_METADW0_CYCLE]), .RST_IN (0), /*AUTOINST*/ // Inputs .CLK (CLK)); // Shift register for input data with output taps for each delayed // cycle. shiftreg #(// Parameters .C_DEPTH (C_RX_PIPELINE_DEPTH), .C_WIDTH (C_PCI_DATA_WIDTH), .C_VALUE (0) /*AUTOINSTPARAM*/) data_shiftreg_inst (// Outputs .RD_DATA (wRxSrData), // Inputs .WR_DATA (M_AXIS_RC_TDATA), .RST_IN (0), /*AUTOINST*/ // Inputs .CLK (CLK)); // Start Flag Shift Register. Data enables are derived from the // taps on this shift register. shiftreg #(// Parameters .C_DEPTH (C_RX_PIPELINE_DEPTH), .C_WIDTH (1'b1), .C_VALUE (0) /*AUTOINSTPARAM*/) sop_shiftreg_inst (// Outputs .RD_DATA (wRxSrSop), // Inputs .WR_DATA (wMAxisRcSop & M_AXIS_RC_TVALID), .RST_IN (0), /*AUTOINST*/ // Inputs .CLK (CLK)); // End Flag Shift Register. shiftreg #(// Parameters .C_DEPTH (C_RX_PIPELINE_DEPTH), .C_WIDTH (1'b1), .C_VALUE (0) /*AUTOINSTPARAM*/) eop_shiftreg_inst (// Outputs .RD_DATA (wRxSrEop), // Inputs .WR_DATA (wMAxisRcTlast), .RST_IN (0), /*AUTOINST*/ // Inputs .CLK (CLK)); // Data Valid Shift Register. Data enables are derived from the // taps on this shift register. shiftreg #(// Parameters .C_DEPTH (C_RX_PIPELINE_DEPTH), .C_WIDTH (1), .C_VALUE (0) /*AUTOINSTPARAM*/) valid_shiftreg_inst (// Outputs .RD_DATA (wRxSrDataValid), // Inputs .WR_DATA (M_AXIS_RC_TVALID), .RST_IN (rRST), /*AUTOINST*/ // Inputs .CLK (CLK)); assign wStartMask = {C_PCI_DATA_WIDTH/32{1'b1}} << ({C_OFFSET_WIDTH{wStartFlag}}& wStartOffset[C_OFFSET_WIDTH-1:0]); offset_to_mask #(// Parameters .C_MASK_SWAP (0), .C_MASK_WIDTH (C_PCI_DATA_WIDTH/32) /*AUTOINSTPARAM*/) o2m_ef (// Outputs .MASK (wEndMask), // Inputs .OFFSET_ENABLE (wEndFlag), .OFFSET (wEndOffset) /*AUTOINST*/); generate if(C_RX_OUTPUT_STAGES == 0) begin assign RXC_DATA_WORD_ENABLE = {wEndMask & wStartMask} & {C_PCI_DATA_WIDTH/32{~rValid | ~wHasPayload}}; end else begin register #(// Parameters .C_WIDTH (C_PCI_DATA_WIDTH/32), .C_VALUE (0) /*AUTOINSTPARAM*/) dw_enable (// Outputs .RD_DATA (wRxcDataWordEnable), // Inputs .RST_IN (~rValid | ~wHasPayload), .WR_DATA (wEndMask & wStartMask), .WR_EN (1), /*AUTOINST*/ // Inputs .CLK (CLK)); pipeline #( // Parameters .C_DEPTH (C_RX_OUTPUT_STAGES-1), .C_WIDTH (C_PCI_DATA_WIDTH/32), .C_USE_MEMORY (0) /*AUTOINSTPARAM*/) dw_pipeline (// Outputs .WR_DATA_READY (), // Pinned to 1 .RD_DATA (RXC_DATA_WORD_ENABLE), .RD_DATA_VALID (), // Inputs .WR_DATA (wRxcDataWordEnable), .WR_DATA_VALID (1), .RD_DATA_READY (1'b1), .RST_IN (0), /*AUTOINST*/ // Inputs .CLK (CLK)); end endgenerate // Shift register for input data with output taps for each delayed // cycle. pipeline #( // Parameters .C_DEPTH (C_RX_OUTPUT_STAGES), .C_WIDTH (`UPKT_RXC_MAXHDR_W + 2*(1 + clog2(C_PCI_DATA_WIDTH/32))+`SIG_TYPE_W), .C_USE_MEMORY (0) /*AUTOINSTPARAM*/) output_pipeline ( // Outputs .WR_DATA_READY (), // Pinned to 1 .RD_DATA ({wRxcHdr, wRxcDataStartFlag, wRxcDataStartOffset,wRxcDataEndFlag, wRxcDataEndOffset,wRxcType}), .RD_DATA_VALID (wRxcDataValid), // Inputs .WR_DATA ({wHdr,wStartFlag, wStartOffset[C_OFFSET_WIDTH-1:0], wEndFlag,wEndOffset[C_OFFSET_WIDTH-1:0],wType}), .WR_DATA_VALID (rValid), .RD_DATA_READY (1'b1), .RST_IN (rRST), /*AUTOINST*/ // Inputs .CLK (CLK)); endmodule // Local Variables: // verilog-library-directories:("." "../../../common/") // End:
//Legal Notice: (C)2017 Altera Corporation. All rights reserved. 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 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. // synthesis translate_off `timescale 1ns / 1ps // synthesis translate_on // turn off superfluous verilog processor warnings // altera message_level Level1 // altera message_off 10034 10035 10036 10037 10230 10240 10030 module soc_design_niosII_core_cpu_test_bench ( // inputs: A_cmp_result, A_ctrl_ld_non_bypass, A_en, A_exc_active_no_break_no_crst, A_exc_allowed, A_exc_any_active, A_exc_hbreak_pri1, A_exc_highest_pri_exc_id, A_exc_inst_fetch, A_exc_norm_intr_pri5, A_st_data, A_valid, A_wr_data_unfiltered, A_wr_dst_reg, E_add_br_to_taken_history_unfiltered, M_bht_ptr_unfiltered, M_bht_wr_data_unfiltered, M_bht_wr_en_unfiltered, M_mem_baddr, M_target_pcb, M_valid, W_badaddr_reg, W_bstatus_reg, W_dst_regnum, W_estatus_reg, W_exception_reg, W_iw, W_iw_op, W_iw_opx, W_pcb, W_status_reg, W_valid, W_vinst, W_wr_dst_reg, clk, d_address, d_byteenable, d_read, d_readdatavalid, d_write, i_address, i_read, i_readdatavalid, reset_n, // outputs: A_wr_data_filtered, E_add_br_to_taken_history_filtered, M_bht_ptr_filtered, M_bht_wr_data_filtered, M_bht_wr_en_filtered, test_has_ended ) ; output [ 31: 0] A_wr_data_filtered; output E_add_br_to_taken_history_filtered; output [ 7: 0] M_bht_ptr_filtered; output [ 1: 0] M_bht_wr_data_filtered; output M_bht_wr_en_filtered; output test_has_ended; input A_cmp_result; input A_ctrl_ld_non_bypass; input A_en; input A_exc_active_no_break_no_crst; input A_exc_allowed; input A_exc_any_active; input A_exc_hbreak_pri1; input [ 31: 0] A_exc_highest_pri_exc_id; input A_exc_inst_fetch; input A_exc_norm_intr_pri5; input [ 31: 0] A_st_data; input A_valid; input [ 31: 0] A_wr_data_unfiltered; input A_wr_dst_reg; input E_add_br_to_taken_history_unfiltered; input [ 7: 0] M_bht_ptr_unfiltered; input [ 1: 0] M_bht_wr_data_unfiltered; input M_bht_wr_en_unfiltered; input [ 26: 0] M_mem_baddr; input [ 26: 0] M_target_pcb; input M_valid; input [ 31: 0] W_badaddr_reg; input [ 31: 0] W_bstatus_reg; input [ 4: 0] W_dst_regnum; input [ 31: 0] W_estatus_reg; input [ 31: 0] W_exception_reg; input [ 31: 0] W_iw; input [ 5: 0] W_iw_op; input [ 5: 0] W_iw_opx; input [ 26: 0] W_pcb; input [ 31: 0] W_status_reg; input W_valid; input [ 71: 0] W_vinst; input W_wr_dst_reg; input clk; input [ 26: 0] d_address; input [ 3: 0] d_byteenable; input d_read; input d_readdatavalid; input d_write; input [ 26: 0] i_address; input i_read; input i_readdatavalid; input reset_n; wire A_iw_invalid; reg [ 26: 0] A_mem_baddr; reg [ 26: 0] A_target_pcb; wire [ 31: 0] A_wr_data_filtered; wire A_wr_data_unfiltered_0_is_x; wire A_wr_data_unfiltered_10_is_x; wire A_wr_data_unfiltered_11_is_x; wire A_wr_data_unfiltered_12_is_x; wire A_wr_data_unfiltered_13_is_x; wire A_wr_data_unfiltered_14_is_x; wire A_wr_data_unfiltered_15_is_x; wire A_wr_data_unfiltered_16_is_x; wire A_wr_data_unfiltered_17_is_x; wire A_wr_data_unfiltered_18_is_x; wire A_wr_data_unfiltered_19_is_x; wire A_wr_data_unfiltered_1_is_x; wire A_wr_data_unfiltered_20_is_x; wire A_wr_data_unfiltered_21_is_x; wire A_wr_data_unfiltered_22_is_x; wire A_wr_data_unfiltered_23_is_x; wire A_wr_data_unfiltered_24_is_x; wire A_wr_data_unfiltered_25_is_x; wire A_wr_data_unfiltered_26_is_x; wire A_wr_data_unfiltered_27_is_x; wire A_wr_data_unfiltered_28_is_x; wire A_wr_data_unfiltered_29_is_x; wire A_wr_data_unfiltered_2_is_x; wire A_wr_data_unfiltered_30_is_x; wire A_wr_data_unfiltered_31_is_x; wire A_wr_data_unfiltered_3_is_x; wire A_wr_data_unfiltered_4_is_x; wire A_wr_data_unfiltered_5_is_x; wire A_wr_data_unfiltered_6_is_x; wire A_wr_data_unfiltered_7_is_x; wire A_wr_data_unfiltered_8_is_x; wire A_wr_data_unfiltered_9_is_x; wire E_add_br_to_taken_history_filtered; wire E_add_br_to_taken_history_unfiltered_is_x; wire [ 7: 0] M_bht_ptr_filtered; wire M_bht_ptr_unfiltered_0_is_x; wire M_bht_ptr_unfiltered_1_is_x; wire M_bht_ptr_unfiltered_2_is_x; wire M_bht_ptr_unfiltered_3_is_x; wire M_bht_ptr_unfiltered_4_is_x; wire M_bht_ptr_unfiltered_5_is_x; wire M_bht_ptr_unfiltered_6_is_x; wire M_bht_ptr_unfiltered_7_is_x; wire [ 1: 0] M_bht_wr_data_filtered; wire M_bht_wr_data_unfiltered_0_is_x; wire M_bht_wr_data_unfiltered_1_is_x; wire M_bht_wr_en_filtered; wire M_bht_wr_en_unfiltered_is_x; reg W_cmp_result; reg W_exc_any_active; reg [ 31: 0] W_exc_highest_pri_exc_id; wire W_is_opx_inst; reg W_iw_invalid; wire W_op_add; wire W_op_addi; wire W_op_and; wire W_op_andhi; wire W_op_andi; wire W_op_beq; wire W_op_bge; wire W_op_bgeu; wire W_op_blt; wire W_op_bltu; wire W_op_bne; wire W_op_br; wire W_op_break; wire W_op_bret; wire W_op_call; wire W_op_callr; wire W_op_cmpeq; wire W_op_cmpeqi; wire W_op_cmpge; wire W_op_cmpgei; wire W_op_cmpgeu; wire W_op_cmpgeui; wire W_op_cmplt; wire W_op_cmplti; wire W_op_cmpltu; wire W_op_cmpltui; wire W_op_cmpne; wire W_op_cmpnei; wire W_op_crst; wire W_op_custom; wire W_op_div; wire W_op_divu; wire W_op_eret; wire W_op_flushd; wire W_op_flushda; wire W_op_flushi; wire W_op_flushp; wire W_op_hbreak; wire W_op_initd; wire W_op_initda; wire W_op_initi; wire W_op_intr; wire W_op_jmp; wire W_op_jmpi; wire W_op_ldb; wire W_op_ldbio; wire W_op_ldbu; wire W_op_ldbuio; wire W_op_ldh; wire W_op_ldhio; wire W_op_ldhu; wire W_op_ldhuio; wire W_op_ldl; wire W_op_ldw; wire W_op_ldwio; wire W_op_mul; wire W_op_muli; wire W_op_mulxss; wire W_op_mulxsu; wire W_op_mulxuu; wire W_op_nextpc; wire W_op_nor; wire W_op_op_rsv02; wire W_op_op_rsv09; wire W_op_op_rsv10; wire W_op_op_rsv17; wire W_op_op_rsv18; wire W_op_op_rsv25; wire W_op_op_rsv26; wire W_op_op_rsv33; wire W_op_op_rsv34; wire W_op_op_rsv41; wire W_op_op_rsv42; wire W_op_op_rsv49; wire W_op_op_rsv57; wire W_op_op_rsv61; wire W_op_op_rsv62; wire W_op_op_rsv63; wire W_op_opx_rsv00; wire W_op_opx_rsv10; wire W_op_opx_rsv15; wire W_op_opx_rsv17; wire W_op_opx_rsv21; wire W_op_opx_rsv25; wire W_op_opx_rsv33; wire W_op_opx_rsv34; wire W_op_opx_rsv35; wire W_op_opx_rsv42; wire W_op_opx_rsv43; wire W_op_opx_rsv44; wire W_op_opx_rsv47; wire W_op_opx_rsv50; wire W_op_opx_rsv51; wire W_op_opx_rsv55; wire W_op_opx_rsv56; wire W_op_opx_rsv60; wire W_op_opx_rsv63; wire W_op_or; wire W_op_orhi; wire W_op_ori; wire W_op_rdctl; wire W_op_rdprs; wire W_op_ret; wire W_op_rol; wire W_op_roli; wire W_op_ror; wire W_op_sll; wire W_op_slli; wire W_op_sra; wire W_op_srai; wire W_op_srl; wire W_op_srli; wire W_op_stb; wire W_op_stbio; wire W_op_stc; wire W_op_sth; wire W_op_sthio; wire W_op_stw; wire W_op_stwio; wire W_op_sub; wire W_op_sync; wire W_op_trap; wire W_op_wrctl; wire W_op_wrprs; wire W_op_xor; wire W_op_xorhi; wire W_op_xori; reg [ 31: 0] W_st_data; reg [ 26: 0] W_target_pcb; reg W_valid_crst; reg W_valid_hbreak; reg W_valid_intr; reg [ 31: 0] W_wr_data_filtered; wire test_has_ended; assign W_op_call = W_iw_op == 0; assign W_op_jmpi = W_iw_op == 1; assign W_op_op_rsv02 = W_iw_op == 2; assign W_op_ldbu = W_iw_op == 3; assign W_op_addi = W_iw_op == 4; assign W_op_stb = W_iw_op == 5; assign W_op_br = W_iw_op == 6; assign W_op_ldb = W_iw_op == 7; assign W_op_cmpgei = W_iw_op == 8; assign W_op_op_rsv09 = W_iw_op == 9; assign W_op_op_rsv10 = W_iw_op == 10; assign W_op_ldhu = W_iw_op == 11; assign W_op_andi = W_iw_op == 12; assign W_op_sth = W_iw_op == 13; assign W_op_bge = W_iw_op == 14; assign W_op_ldh = W_iw_op == 15; assign W_op_cmplti = W_iw_op == 16; assign W_op_op_rsv17 = W_iw_op == 17; assign W_op_op_rsv18 = W_iw_op == 18; assign W_op_initda = W_iw_op == 19; assign W_op_ori = W_iw_op == 20; assign W_op_stw = W_iw_op == 21; assign W_op_blt = W_iw_op == 22; assign W_op_ldw = W_iw_op == 23; assign W_op_cmpnei = W_iw_op == 24; assign W_op_op_rsv25 = W_iw_op == 25; assign W_op_op_rsv26 = W_iw_op == 26; assign W_op_flushda = W_iw_op == 27; assign W_op_xori = W_iw_op == 28; assign W_op_stc = W_iw_op == 29; assign W_op_bne = W_iw_op == 30; assign W_op_ldl = W_iw_op == 31; assign W_op_cmpeqi = W_iw_op == 32; assign W_op_op_rsv33 = W_iw_op == 33; assign W_op_op_rsv34 = W_iw_op == 34; assign W_op_ldbuio = W_iw_op == 35; assign W_op_muli = W_iw_op == 36; assign W_op_stbio = W_iw_op == 37; assign W_op_beq = W_iw_op == 38; assign W_op_ldbio = W_iw_op == 39; assign W_op_cmpgeui = W_iw_op == 40; assign W_op_op_rsv41 = W_iw_op == 41; assign W_op_op_rsv42 = W_iw_op == 42; assign W_op_ldhuio = W_iw_op == 43; assign W_op_andhi = W_iw_op == 44; assign W_op_sthio = W_iw_op == 45; assign W_op_bgeu = W_iw_op == 46; assign W_op_ldhio = W_iw_op == 47; assign W_op_cmpltui = W_iw_op == 48; assign W_op_op_rsv49 = W_iw_op == 49; assign W_op_custom = W_iw_op == 50; assign W_op_initd = W_iw_op == 51; assign W_op_orhi = W_iw_op == 52; assign W_op_stwio = W_iw_op == 53; assign W_op_bltu = W_iw_op == 54; assign W_op_ldwio = W_iw_op == 55; assign W_op_rdprs = W_iw_op == 56; assign W_op_op_rsv57 = W_iw_op == 57; assign W_op_flushd = W_iw_op == 59; assign W_op_xorhi = W_iw_op == 60; assign W_op_op_rsv61 = W_iw_op == 61; assign W_op_op_rsv62 = W_iw_op == 62; assign W_op_op_rsv63 = W_iw_op == 63; assign W_op_opx_rsv00 = (W_iw_opx == 0) & W_is_opx_inst; assign W_op_eret = (W_iw_opx == 1) & W_is_opx_inst; assign W_op_roli = (W_iw_opx == 2) & W_is_opx_inst; assign W_op_rol = (W_iw_opx == 3) & W_is_opx_inst; assign W_op_flushp = (W_iw_opx == 4) & W_is_opx_inst; assign W_op_ret = (W_iw_opx == 5) & W_is_opx_inst; assign W_op_nor = (W_iw_opx == 6) & W_is_opx_inst; assign W_op_mulxuu = (W_iw_opx == 7) & W_is_opx_inst; assign W_op_cmpge = (W_iw_opx == 8) & W_is_opx_inst; assign W_op_bret = (W_iw_opx == 9) & W_is_opx_inst; assign W_op_opx_rsv10 = (W_iw_opx == 10) & W_is_opx_inst; assign W_op_ror = (W_iw_opx == 11) & W_is_opx_inst; assign W_op_flushi = (W_iw_opx == 12) & W_is_opx_inst; assign W_op_jmp = (W_iw_opx == 13) & W_is_opx_inst; assign W_op_and = (W_iw_opx == 14) & W_is_opx_inst; assign W_op_opx_rsv15 = (W_iw_opx == 15) & W_is_opx_inst; assign W_op_cmplt = (W_iw_opx == 16) & W_is_opx_inst; assign W_op_opx_rsv17 = (W_iw_opx == 17) & W_is_opx_inst; assign W_op_slli = (W_iw_opx == 18) & W_is_opx_inst; assign W_op_sll = (W_iw_opx == 19) & W_is_opx_inst; assign W_op_wrprs = (W_iw_opx == 20) & W_is_opx_inst; assign W_op_opx_rsv21 = (W_iw_opx == 21) & W_is_opx_inst; assign W_op_or = (W_iw_opx == 22) & W_is_opx_inst; assign W_op_mulxsu = (W_iw_opx == 23) & W_is_opx_inst; assign W_op_cmpne = (W_iw_opx == 24) & W_is_opx_inst; assign W_op_opx_rsv25 = (W_iw_opx == 25) & W_is_opx_inst; assign W_op_srli = (W_iw_opx == 26) & W_is_opx_inst; assign W_op_srl = (W_iw_opx == 27) & W_is_opx_inst; assign W_op_nextpc = (W_iw_opx == 28) & W_is_opx_inst; assign W_op_callr = (W_iw_opx == 29) & W_is_opx_inst; assign W_op_xor = (W_iw_opx == 30) & W_is_opx_inst; assign W_op_mulxss = (W_iw_opx == 31) & W_is_opx_inst; assign W_op_cmpeq = (W_iw_opx == 32) & W_is_opx_inst; assign W_op_opx_rsv33 = (W_iw_opx == 33) & W_is_opx_inst; assign W_op_opx_rsv34 = (W_iw_opx == 34) & W_is_opx_inst; assign W_op_opx_rsv35 = (W_iw_opx == 35) & W_is_opx_inst; assign W_op_divu = (W_iw_opx == 36) & W_is_opx_inst; assign W_op_div = (W_iw_opx == 37) & W_is_opx_inst; assign W_op_rdctl = (W_iw_opx == 38) & W_is_opx_inst; assign W_op_mul = (W_iw_opx == 39) & W_is_opx_inst; assign W_op_cmpgeu = (W_iw_opx == 40) & W_is_opx_inst; assign W_op_initi = (W_iw_opx == 41) & W_is_opx_inst; assign W_op_opx_rsv42 = (W_iw_opx == 42) & W_is_opx_inst; assign W_op_opx_rsv43 = (W_iw_opx == 43) & W_is_opx_inst; assign W_op_opx_rsv44 = (W_iw_opx == 44) & W_is_opx_inst; assign W_op_trap = (W_iw_opx == 45) & W_is_opx_inst; assign W_op_wrctl = (W_iw_opx == 46) & W_is_opx_inst; assign W_op_opx_rsv47 = (W_iw_opx == 47) & W_is_opx_inst; assign W_op_cmpltu = (W_iw_opx == 48) & W_is_opx_inst; assign W_op_add = (W_iw_opx == 49) & W_is_opx_inst; assign W_op_opx_rsv50 = (W_iw_opx == 50) & W_is_opx_inst; assign W_op_opx_rsv51 = (W_iw_opx == 51) & W_is_opx_inst; assign W_op_break = (W_iw_opx == 52) & W_is_opx_inst; assign W_op_hbreak = (W_iw_opx == 53) & W_is_opx_inst; assign W_op_sync = (W_iw_opx == 54) & W_is_opx_inst; assign W_op_opx_rsv55 = (W_iw_opx == 55) & W_is_opx_inst; assign W_op_opx_rsv56 = (W_iw_opx == 56) & W_is_opx_inst; assign W_op_sub = (W_iw_opx == 57) & W_is_opx_inst; assign W_op_srai = (W_iw_opx == 58) & W_is_opx_inst; assign W_op_sra = (W_iw_opx == 59) & W_is_opx_inst; assign W_op_opx_rsv60 = (W_iw_opx == 60) & W_is_opx_inst; assign W_op_intr = (W_iw_opx == 61) & W_is_opx_inst; assign W_op_crst = (W_iw_opx == 62) & W_is_opx_inst; assign W_op_opx_rsv63 = (W_iw_opx == 63) & W_is_opx_inst; assign W_is_opx_inst = W_iw_op == 58; always @(posedge clk or negedge reset_n) begin if (reset_n == 0) A_target_pcb <= 0; else if (A_en) A_target_pcb <= M_target_pcb; end always @(posedge clk or negedge reset_n) begin if (reset_n == 0) A_mem_baddr <= 0; else if (A_en) A_mem_baddr <= M_mem_baddr; end always @(posedge clk or negedge reset_n) begin if (reset_n == 0) W_wr_data_filtered <= 0; else W_wr_data_filtered <= A_wr_data_filtered; end always @(posedge clk or negedge reset_n) begin if (reset_n == 0) W_st_data <= 0; else W_st_data <= A_st_data; end always @(posedge clk or negedge reset_n) begin if (reset_n == 0) W_cmp_result <= 0; else W_cmp_result <= A_cmp_result; end always @(posedge clk or negedge reset_n) begin if (reset_n == 0) W_target_pcb <= 0; else W_target_pcb <= A_target_pcb; end always @(posedge clk or negedge reset_n) begin if (reset_n == 0) W_valid_hbreak <= 0; else W_valid_hbreak <= A_exc_allowed & A_exc_hbreak_pri1; end always @(posedge clk or negedge reset_n) begin if (reset_n == 0) W_valid_crst <= 0; else W_valid_crst <= A_exc_allowed & 0; end always @(posedge clk or negedge reset_n) begin if (reset_n == 0) W_valid_intr <= 0; else W_valid_intr <= A_exc_allowed & A_exc_norm_intr_pri5; end always @(posedge clk or negedge reset_n) begin if (reset_n == 0) W_exc_any_active <= 0; else W_exc_any_active <= A_exc_any_active; end always @(posedge clk or negedge reset_n) begin if (reset_n == 0) W_exc_highest_pri_exc_id <= 0; else W_exc_highest_pri_exc_id <= A_exc_highest_pri_exc_id; end assign A_iw_invalid = A_exc_inst_fetch & A_exc_active_no_break_no_crst; always @(posedge clk or negedge reset_n) begin if (reset_n == 0) W_iw_invalid <= 0; else W_iw_invalid <= A_iw_invalid; end assign test_has_ended = 1'b0; //synthesis translate_off //////////////// SIMULATION-ONLY CONTENTS //Clearing 'X' data bits assign A_wr_data_unfiltered_0_is_x = ^(A_wr_data_unfiltered[0]) === 1'bx; assign A_wr_data_filtered[0] = (A_wr_data_unfiltered_0_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[0]; assign A_wr_data_unfiltered_1_is_x = ^(A_wr_data_unfiltered[1]) === 1'bx; assign A_wr_data_filtered[1] = (A_wr_data_unfiltered_1_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[1]; assign A_wr_data_unfiltered_2_is_x = ^(A_wr_data_unfiltered[2]) === 1'bx; assign A_wr_data_filtered[2] = (A_wr_data_unfiltered_2_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[2]; assign A_wr_data_unfiltered_3_is_x = ^(A_wr_data_unfiltered[3]) === 1'bx; assign A_wr_data_filtered[3] = (A_wr_data_unfiltered_3_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[3]; assign A_wr_data_unfiltered_4_is_x = ^(A_wr_data_unfiltered[4]) === 1'bx; assign A_wr_data_filtered[4] = (A_wr_data_unfiltered_4_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[4]; assign A_wr_data_unfiltered_5_is_x = ^(A_wr_data_unfiltered[5]) === 1'bx; assign A_wr_data_filtered[5] = (A_wr_data_unfiltered_5_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[5]; assign A_wr_data_unfiltered_6_is_x = ^(A_wr_data_unfiltered[6]) === 1'bx; assign A_wr_data_filtered[6] = (A_wr_data_unfiltered_6_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[6]; assign A_wr_data_unfiltered_7_is_x = ^(A_wr_data_unfiltered[7]) === 1'bx; assign A_wr_data_filtered[7] = (A_wr_data_unfiltered_7_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[7]; assign A_wr_data_unfiltered_8_is_x = ^(A_wr_data_unfiltered[8]) === 1'bx; assign A_wr_data_filtered[8] = (A_wr_data_unfiltered_8_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[8]; assign A_wr_data_unfiltered_9_is_x = ^(A_wr_data_unfiltered[9]) === 1'bx; assign A_wr_data_filtered[9] = (A_wr_data_unfiltered_9_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[9]; assign A_wr_data_unfiltered_10_is_x = ^(A_wr_data_unfiltered[10]) === 1'bx; assign A_wr_data_filtered[10] = (A_wr_data_unfiltered_10_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[10]; assign A_wr_data_unfiltered_11_is_x = ^(A_wr_data_unfiltered[11]) === 1'bx; assign A_wr_data_filtered[11] = (A_wr_data_unfiltered_11_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[11]; assign A_wr_data_unfiltered_12_is_x = ^(A_wr_data_unfiltered[12]) === 1'bx; assign A_wr_data_filtered[12] = (A_wr_data_unfiltered_12_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[12]; assign A_wr_data_unfiltered_13_is_x = ^(A_wr_data_unfiltered[13]) === 1'bx; assign A_wr_data_filtered[13] = (A_wr_data_unfiltered_13_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[13]; assign A_wr_data_unfiltered_14_is_x = ^(A_wr_data_unfiltered[14]) === 1'bx; assign A_wr_data_filtered[14] = (A_wr_data_unfiltered_14_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[14]; assign A_wr_data_unfiltered_15_is_x = ^(A_wr_data_unfiltered[15]) === 1'bx; assign A_wr_data_filtered[15] = (A_wr_data_unfiltered_15_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[15]; assign A_wr_data_unfiltered_16_is_x = ^(A_wr_data_unfiltered[16]) === 1'bx; assign A_wr_data_filtered[16] = (A_wr_data_unfiltered_16_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[16]; assign A_wr_data_unfiltered_17_is_x = ^(A_wr_data_unfiltered[17]) === 1'bx; assign A_wr_data_filtered[17] = (A_wr_data_unfiltered_17_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[17]; assign A_wr_data_unfiltered_18_is_x = ^(A_wr_data_unfiltered[18]) === 1'bx; assign A_wr_data_filtered[18] = (A_wr_data_unfiltered_18_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[18]; assign A_wr_data_unfiltered_19_is_x = ^(A_wr_data_unfiltered[19]) === 1'bx; assign A_wr_data_filtered[19] = (A_wr_data_unfiltered_19_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[19]; assign A_wr_data_unfiltered_20_is_x = ^(A_wr_data_unfiltered[20]) === 1'bx; assign A_wr_data_filtered[20] = (A_wr_data_unfiltered_20_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[20]; assign A_wr_data_unfiltered_21_is_x = ^(A_wr_data_unfiltered[21]) === 1'bx; assign A_wr_data_filtered[21] = (A_wr_data_unfiltered_21_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[21]; assign A_wr_data_unfiltered_22_is_x = ^(A_wr_data_unfiltered[22]) === 1'bx; assign A_wr_data_filtered[22] = (A_wr_data_unfiltered_22_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[22]; assign A_wr_data_unfiltered_23_is_x = ^(A_wr_data_unfiltered[23]) === 1'bx; assign A_wr_data_filtered[23] = (A_wr_data_unfiltered_23_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[23]; assign A_wr_data_unfiltered_24_is_x = ^(A_wr_data_unfiltered[24]) === 1'bx; assign A_wr_data_filtered[24] = (A_wr_data_unfiltered_24_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[24]; assign A_wr_data_unfiltered_25_is_x = ^(A_wr_data_unfiltered[25]) === 1'bx; assign A_wr_data_filtered[25] = (A_wr_data_unfiltered_25_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[25]; assign A_wr_data_unfiltered_26_is_x = ^(A_wr_data_unfiltered[26]) === 1'bx; assign A_wr_data_filtered[26] = (A_wr_data_unfiltered_26_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[26]; assign A_wr_data_unfiltered_27_is_x = ^(A_wr_data_unfiltered[27]) === 1'bx; assign A_wr_data_filtered[27] = (A_wr_data_unfiltered_27_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[27]; assign A_wr_data_unfiltered_28_is_x = ^(A_wr_data_unfiltered[28]) === 1'bx; assign A_wr_data_filtered[28] = (A_wr_data_unfiltered_28_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[28]; assign A_wr_data_unfiltered_29_is_x = ^(A_wr_data_unfiltered[29]) === 1'bx; assign A_wr_data_filtered[29] = (A_wr_data_unfiltered_29_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[29]; assign A_wr_data_unfiltered_30_is_x = ^(A_wr_data_unfiltered[30]) === 1'bx; assign A_wr_data_filtered[30] = (A_wr_data_unfiltered_30_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[30]; assign A_wr_data_unfiltered_31_is_x = ^(A_wr_data_unfiltered[31]) === 1'bx; assign A_wr_data_filtered[31] = (A_wr_data_unfiltered_31_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[31]; //Clearing 'X' data bits assign E_add_br_to_taken_history_unfiltered_is_x = ^(E_add_br_to_taken_history_unfiltered) === 1'bx; assign E_add_br_to_taken_history_filtered = E_add_br_to_taken_history_unfiltered_is_x ? 1'b0 : E_add_br_to_taken_history_unfiltered; //Clearing 'X' data bits assign M_bht_wr_en_unfiltered_is_x = ^(M_bht_wr_en_unfiltered) === 1'bx; assign M_bht_wr_en_filtered = M_bht_wr_en_unfiltered_is_x ? 1'b0 : M_bht_wr_en_unfiltered; //Clearing 'X' data bits assign M_bht_wr_data_unfiltered_0_is_x = ^(M_bht_wr_data_unfiltered[0]) === 1'bx; assign M_bht_wr_data_filtered[0] = M_bht_wr_data_unfiltered_0_is_x ? 1'b0 : M_bht_wr_data_unfiltered[0]; assign M_bht_wr_data_unfiltered_1_is_x = ^(M_bht_wr_data_unfiltered[1]) === 1'bx; assign M_bht_wr_data_filtered[1] = M_bht_wr_data_unfiltered_1_is_x ? 1'b0 : M_bht_wr_data_unfiltered[1]; //Clearing 'X' data bits assign M_bht_ptr_unfiltered_0_is_x = ^(M_bht_ptr_unfiltered[0]) === 1'bx; assign M_bht_ptr_filtered[0] = M_bht_ptr_unfiltered_0_is_x ? 1'b0 : M_bht_ptr_unfiltered[0]; assign M_bht_ptr_unfiltered_1_is_x = ^(M_bht_ptr_unfiltered[1]) === 1'bx; assign M_bht_ptr_filtered[1] = M_bht_ptr_unfiltered_1_is_x ? 1'b0 : M_bht_ptr_unfiltered[1]; assign M_bht_ptr_unfiltered_2_is_x = ^(M_bht_ptr_unfiltered[2]) === 1'bx; assign M_bht_ptr_filtered[2] = M_bht_ptr_unfiltered_2_is_x ? 1'b0 : M_bht_ptr_unfiltered[2]; assign M_bht_ptr_unfiltered_3_is_x = ^(M_bht_ptr_unfiltered[3]) === 1'bx; assign M_bht_ptr_filtered[3] = M_bht_ptr_unfiltered_3_is_x ? 1'b0 : M_bht_ptr_unfiltered[3]; assign M_bht_ptr_unfiltered_4_is_x = ^(M_bht_ptr_unfiltered[4]) === 1'bx; assign M_bht_ptr_filtered[4] = M_bht_ptr_unfiltered_4_is_x ? 1'b0 : M_bht_ptr_unfiltered[4]; assign M_bht_ptr_unfiltered_5_is_x = ^(M_bht_ptr_unfiltered[5]) === 1'bx; assign M_bht_ptr_filtered[5] = M_bht_ptr_unfiltered_5_is_x ? 1'b0 : M_bht_ptr_unfiltered[5]; assign M_bht_ptr_unfiltered_6_is_x = ^(M_bht_ptr_unfiltered[6]) === 1'bx; assign M_bht_ptr_filtered[6] = M_bht_ptr_unfiltered_6_is_x ? 1'b0 : M_bht_ptr_unfiltered[6]; assign M_bht_ptr_unfiltered_7_is_x = ^(M_bht_ptr_unfiltered[7]) === 1'bx; assign M_bht_ptr_filtered[7] = M_bht_ptr_unfiltered_7_is_x ? 1'b0 : M_bht_ptr_unfiltered[7]; always @(posedge clk) begin if (reset_n) if (^(W_wr_dst_reg) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/W_wr_dst_reg is 'x'\n", $time); $stop; end end always @(posedge clk or negedge reset_n) begin if (reset_n == 0) begin end else if (W_wr_dst_reg) if (^(W_dst_regnum) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/W_dst_regnum is 'x'\n", $time); $stop; end end always @(posedge clk) begin if (reset_n) if (^(W_valid) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/W_valid is 'x'\n", $time); $stop; end end always @(posedge clk or negedge reset_n) begin if (reset_n == 0) begin end else if (W_valid) if (^(W_pcb) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/W_pcb is 'x'\n", $time); $stop; end end always @(posedge clk or negedge reset_n) begin if (reset_n == 0) begin end else if (W_valid) if (^(W_iw) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/W_iw is 'x'\n", $time); $stop; end end always @(posedge clk) begin if (reset_n) if (^(A_en) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/A_en is 'x'\n", $time); $stop; end end always @(posedge clk) begin if (reset_n) if (^(M_valid) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/M_valid is 'x'\n", $time); $stop; end end always @(posedge clk) begin if (reset_n) if (^(A_valid) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/A_valid is 'x'\n", $time); $stop; end end always @(posedge clk or negedge reset_n) begin if (reset_n == 0) begin end else if (A_valid & A_en & A_wr_dst_reg) if (^(A_wr_data_unfiltered) === 1'bx) begin $write("%0d ns: WARNING: soc_design_niosII_core_cpu_test_bench/A_wr_data_unfiltered is 'x'\n", $time); end end always @(posedge clk) begin if (reset_n) if (^(W_status_reg) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/W_status_reg is 'x'\n", $time); $stop; end end always @(posedge clk) begin if (reset_n) if (^(W_estatus_reg) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/W_estatus_reg is 'x'\n", $time); $stop; end end always @(posedge clk) begin if (reset_n) if (^(W_bstatus_reg) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/W_bstatus_reg is 'x'\n", $time); $stop; end end always @(posedge clk) begin if (reset_n) if (^(W_exception_reg) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/W_exception_reg is 'x'\n", $time); $stop; end end always @(posedge clk) begin if (reset_n) if (^(W_badaddr_reg) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/W_badaddr_reg is 'x'\n", $time); $stop; end end always @(posedge clk) begin if (reset_n) if (^(A_exc_any_active) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/A_exc_any_active is 'x'\n", $time); $stop; end end always @(posedge clk) begin if (reset_n) if (^(i_read) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/i_read is 'x'\n", $time); $stop; end end always @(posedge clk or negedge reset_n) begin if (reset_n == 0) begin end else if (i_read) if (^(i_address) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/i_address is 'x'\n", $time); $stop; end end always @(posedge clk) begin if (reset_n) if (^(d_write) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/d_write is 'x'\n", $time); $stop; end end always @(posedge clk or negedge reset_n) begin if (reset_n == 0) begin end else if (d_write) if (^(d_byteenable) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/d_byteenable is 'x'\n", $time); $stop; end end always @(posedge clk or negedge reset_n) begin if (reset_n == 0) begin end else if (d_write | d_read) if (^(d_address) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/d_address is 'x'\n", $time); $stop; end end always @(posedge clk) begin if (reset_n) if (^(d_read) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/d_read is 'x'\n", $time); $stop; end end always @(posedge clk) begin if (reset_n) if (^(i_readdatavalid) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/i_readdatavalid is 'x'\n", $time); $stop; end end always @(posedge clk) begin if (reset_n) if (^(d_readdatavalid) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/d_readdatavalid is 'x'\n", $time); $stop; end end //////////////// END SIMULATION-ONLY CONTENTS //synthesis translate_on //synthesis read_comments_as_HDL on // // assign A_wr_data_filtered = A_wr_data_unfiltered; // // // assign E_add_br_to_taken_history_filtered = E_add_br_to_taken_history_unfiltered; // // // assign M_bht_wr_en_filtered = M_bht_wr_en_unfiltered; // // // assign M_bht_wr_data_filtered = M_bht_wr_data_unfiltered; // // // assign M_bht_ptr_filtered = M_bht_ptr_unfiltered; // //synthesis read_comments_as_HDL off endmodule
//Legal Notice: (C)2017 Altera Corporation. All rights reserved. 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 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. // synthesis translate_off `timescale 1ns / 1ps // synthesis translate_on // turn off superfluous verilog processor warnings // altera message_level Level1 // altera message_off 10034 10035 10036 10037 10230 10240 10030 module soc_design_niosII_core_cpu_test_bench ( // inputs: A_cmp_result, A_ctrl_ld_non_bypass, A_en, A_exc_active_no_break_no_crst, A_exc_allowed, A_exc_any_active, A_exc_hbreak_pri1, A_exc_highest_pri_exc_id, A_exc_inst_fetch, A_exc_norm_intr_pri5, A_st_data, A_valid, A_wr_data_unfiltered, A_wr_dst_reg, E_add_br_to_taken_history_unfiltered, M_bht_ptr_unfiltered, M_bht_wr_data_unfiltered, M_bht_wr_en_unfiltered, M_mem_baddr, M_target_pcb, M_valid, W_badaddr_reg, W_bstatus_reg, W_dst_regnum, W_estatus_reg, W_exception_reg, W_iw, W_iw_op, W_iw_opx, W_pcb, W_status_reg, W_valid, W_vinst, W_wr_dst_reg, clk, d_address, d_byteenable, d_read, d_readdatavalid, d_write, i_address, i_read, i_readdatavalid, reset_n, // outputs: A_wr_data_filtered, E_add_br_to_taken_history_filtered, M_bht_ptr_filtered, M_bht_wr_data_filtered, M_bht_wr_en_filtered, test_has_ended ) ; output [ 31: 0] A_wr_data_filtered; output E_add_br_to_taken_history_filtered; output [ 7: 0] M_bht_ptr_filtered; output [ 1: 0] M_bht_wr_data_filtered; output M_bht_wr_en_filtered; output test_has_ended; input A_cmp_result; input A_ctrl_ld_non_bypass; input A_en; input A_exc_active_no_break_no_crst; input A_exc_allowed; input A_exc_any_active; input A_exc_hbreak_pri1; input [ 31: 0] A_exc_highest_pri_exc_id; input A_exc_inst_fetch; input A_exc_norm_intr_pri5; input [ 31: 0] A_st_data; input A_valid; input [ 31: 0] A_wr_data_unfiltered; input A_wr_dst_reg; input E_add_br_to_taken_history_unfiltered; input [ 7: 0] M_bht_ptr_unfiltered; input [ 1: 0] M_bht_wr_data_unfiltered; input M_bht_wr_en_unfiltered; input [ 26: 0] M_mem_baddr; input [ 26: 0] M_target_pcb; input M_valid; input [ 31: 0] W_badaddr_reg; input [ 31: 0] W_bstatus_reg; input [ 4: 0] W_dst_regnum; input [ 31: 0] W_estatus_reg; input [ 31: 0] W_exception_reg; input [ 31: 0] W_iw; input [ 5: 0] W_iw_op; input [ 5: 0] W_iw_opx; input [ 26: 0] W_pcb; input [ 31: 0] W_status_reg; input W_valid; input [ 71: 0] W_vinst; input W_wr_dst_reg; input clk; input [ 26: 0] d_address; input [ 3: 0] d_byteenable; input d_read; input d_readdatavalid; input d_write; input [ 26: 0] i_address; input i_read; input i_readdatavalid; input reset_n; wire A_iw_invalid; reg [ 26: 0] A_mem_baddr; reg [ 26: 0] A_target_pcb; wire [ 31: 0] A_wr_data_filtered; wire A_wr_data_unfiltered_0_is_x; wire A_wr_data_unfiltered_10_is_x; wire A_wr_data_unfiltered_11_is_x; wire A_wr_data_unfiltered_12_is_x; wire A_wr_data_unfiltered_13_is_x; wire A_wr_data_unfiltered_14_is_x; wire A_wr_data_unfiltered_15_is_x; wire A_wr_data_unfiltered_16_is_x; wire A_wr_data_unfiltered_17_is_x; wire A_wr_data_unfiltered_18_is_x; wire A_wr_data_unfiltered_19_is_x; wire A_wr_data_unfiltered_1_is_x; wire A_wr_data_unfiltered_20_is_x; wire A_wr_data_unfiltered_21_is_x; wire A_wr_data_unfiltered_22_is_x; wire A_wr_data_unfiltered_23_is_x; wire A_wr_data_unfiltered_24_is_x; wire A_wr_data_unfiltered_25_is_x; wire A_wr_data_unfiltered_26_is_x; wire A_wr_data_unfiltered_27_is_x; wire A_wr_data_unfiltered_28_is_x; wire A_wr_data_unfiltered_29_is_x; wire A_wr_data_unfiltered_2_is_x; wire A_wr_data_unfiltered_30_is_x; wire A_wr_data_unfiltered_31_is_x; wire A_wr_data_unfiltered_3_is_x; wire A_wr_data_unfiltered_4_is_x; wire A_wr_data_unfiltered_5_is_x; wire A_wr_data_unfiltered_6_is_x; wire A_wr_data_unfiltered_7_is_x; wire A_wr_data_unfiltered_8_is_x; wire A_wr_data_unfiltered_9_is_x; wire E_add_br_to_taken_history_filtered; wire E_add_br_to_taken_history_unfiltered_is_x; wire [ 7: 0] M_bht_ptr_filtered; wire M_bht_ptr_unfiltered_0_is_x; wire M_bht_ptr_unfiltered_1_is_x; wire M_bht_ptr_unfiltered_2_is_x; wire M_bht_ptr_unfiltered_3_is_x; wire M_bht_ptr_unfiltered_4_is_x; wire M_bht_ptr_unfiltered_5_is_x; wire M_bht_ptr_unfiltered_6_is_x; wire M_bht_ptr_unfiltered_7_is_x; wire [ 1: 0] M_bht_wr_data_filtered; wire M_bht_wr_data_unfiltered_0_is_x; wire M_bht_wr_data_unfiltered_1_is_x; wire M_bht_wr_en_filtered; wire M_bht_wr_en_unfiltered_is_x; reg W_cmp_result; reg W_exc_any_active; reg [ 31: 0] W_exc_highest_pri_exc_id; wire W_is_opx_inst; reg W_iw_invalid; wire W_op_add; wire W_op_addi; wire W_op_and; wire W_op_andhi; wire W_op_andi; wire W_op_beq; wire W_op_bge; wire W_op_bgeu; wire W_op_blt; wire W_op_bltu; wire W_op_bne; wire W_op_br; wire W_op_break; wire W_op_bret; wire W_op_call; wire W_op_callr; wire W_op_cmpeq; wire W_op_cmpeqi; wire W_op_cmpge; wire W_op_cmpgei; wire W_op_cmpgeu; wire W_op_cmpgeui; wire W_op_cmplt; wire W_op_cmplti; wire W_op_cmpltu; wire W_op_cmpltui; wire W_op_cmpne; wire W_op_cmpnei; wire W_op_crst; wire W_op_custom; wire W_op_div; wire W_op_divu; wire W_op_eret; wire W_op_flushd; wire W_op_flushda; wire W_op_flushi; wire W_op_flushp; wire W_op_hbreak; wire W_op_initd; wire W_op_initda; wire W_op_initi; wire W_op_intr; wire W_op_jmp; wire W_op_jmpi; wire W_op_ldb; wire W_op_ldbio; wire W_op_ldbu; wire W_op_ldbuio; wire W_op_ldh; wire W_op_ldhio; wire W_op_ldhu; wire W_op_ldhuio; wire W_op_ldl; wire W_op_ldw; wire W_op_ldwio; wire W_op_mul; wire W_op_muli; wire W_op_mulxss; wire W_op_mulxsu; wire W_op_mulxuu; wire W_op_nextpc; wire W_op_nor; wire W_op_op_rsv02; wire W_op_op_rsv09; wire W_op_op_rsv10; wire W_op_op_rsv17; wire W_op_op_rsv18; wire W_op_op_rsv25; wire W_op_op_rsv26; wire W_op_op_rsv33; wire W_op_op_rsv34; wire W_op_op_rsv41; wire W_op_op_rsv42; wire W_op_op_rsv49; wire W_op_op_rsv57; wire W_op_op_rsv61; wire W_op_op_rsv62; wire W_op_op_rsv63; wire W_op_opx_rsv00; wire W_op_opx_rsv10; wire W_op_opx_rsv15; wire W_op_opx_rsv17; wire W_op_opx_rsv21; wire W_op_opx_rsv25; wire W_op_opx_rsv33; wire W_op_opx_rsv34; wire W_op_opx_rsv35; wire W_op_opx_rsv42; wire W_op_opx_rsv43; wire W_op_opx_rsv44; wire W_op_opx_rsv47; wire W_op_opx_rsv50; wire W_op_opx_rsv51; wire W_op_opx_rsv55; wire W_op_opx_rsv56; wire W_op_opx_rsv60; wire W_op_opx_rsv63; wire W_op_or; wire W_op_orhi; wire W_op_ori; wire W_op_rdctl; wire W_op_rdprs; wire W_op_ret; wire W_op_rol; wire W_op_roli; wire W_op_ror; wire W_op_sll; wire W_op_slli; wire W_op_sra; wire W_op_srai; wire W_op_srl; wire W_op_srli; wire W_op_stb; wire W_op_stbio; wire W_op_stc; wire W_op_sth; wire W_op_sthio; wire W_op_stw; wire W_op_stwio; wire W_op_sub; wire W_op_sync; wire W_op_trap; wire W_op_wrctl; wire W_op_wrprs; wire W_op_xor; wire W_op_xorhi; wire W_op_xori; reg [ 31: 0] W_st_data; reg [ 26: 0] W_target_pcb; reg W_valid_crst; reg W_valid_hbreak; reg W_valid_intr; reg [ 31: 0] W_wr_data_filtered; wire test_has_ended; assign W_op_call = W_iw_op == 0; assign W_op_jmpi = W_iw_op == 1; assign W_op_op_rsv02 = W_iw_op == 2; assign W_op_ldbu = W_iw_op == 3; assign W_op_addi = W_iw_op == 4; assign W_op_stb = W_iw_op == 5; assign W_op_br = W_iw_op == 6; assign W_op_ldb = W_iw_op == 7; assign W_op_cmpgei = W_iw_op == 8; assign W_op_op_rsv09 = W_iw_op == 9; assign W_op_op_rsv10 = W_iw_op == 10; assign W_op_ldhu = W_iw_op == 11; assign W_op_andi = W_iw_op == 12; assign W_op_sth = W_iw_op == 13; assign W_op_bge = W_iw_op == 14; assign W_op_ldh = W_iw_op == 15; assign W_op_cmplti = W_iw_op == 16; assign W_op_op_rsv17 = W_iw_op == 17; assign W_op_op_rsv18 = W_iw_op == 18; assign W_op_initda = W_iw_op == 19; assign W_op_ori = W_iw_op == 20; assign W_op_stw = W_iw_op == 21; assign W_op_blt = W_iw_op == 22; assign W_op_ldw = W_iw_op == 23; assign W_op_cmpnei = W_iw_op == 24; assign W_op_op_rsv25 = W_iw_op == 25; assign W_op_op_rsv26 = W_iw_op == 26; assign W_op_flushda = W_iw_op == 27; assign W_op_xori = W_iw_op == 28; assign W_op_stc = W_iw_op == 29; assign W_op_bne = W_iw_op == 30; assign W_op_ldl = W_iw_op == 31; assign W_op_cmpeqi = W_iw_op == 32; assign W_op_op_rsv33 = W_iw_op == 33; assign W_op_op_rsv34 = W_iw_op == 34; assign W_op_ldbuio = W_iw_op == 35; assign W_op_muli = W_iw_op == 36; assign W_op_stbio = W_iw_op == 37; assign W_op_beq = W_iw_op == 38; assign W_op_ldbio = W_iw_op == 39; assign W_op_cmpgeui = W_iw_op == 40; assign W_op_op_rsv41 = W_iw_op == 41; assign W_op_op_rsv42 = W_iw_op == 42; assign W_op_ldhuio = W_iw_op == 43; assign W_op_andhi = W_iw_op == 44; assign W_op_sthio = W_iw_op == 45; assign W_op_bgeu = W_iw_op == 46; assign W_op_ldhio = W_iw_op == 47; assign W_op_cmpltui = W_iw_op == 48; assign W_op_op_rsv49 = W_iw_op == 49; assign W_op_custom = W_iw_op == 50; assign W_op_initd = W_iw_op == 51; assign W_op_orhi = W_iw_op == 52; assign W_op_stwio = W_iw_op == 53; assign W_op_bltu = W_iw_op == 54; assign W_op_ldwio = W_iw_op == 55; assign W_op_rdprs = W_iw_op == 56; assign W_op_op_rsv57 = W_iw_op == 57; assign W_op_flushd = W_iw_op == 59; assign W_op_xorhi = W_iw_op == 60; assign W_op_op_rsv61 = W_iw_op == 61; assign W_op_op_rsv62 = W_iw_op == 62; assign W_op_op_rsv63 = W_iw_op == 63; assign W_op_opx_rsv00 = (W_iw_opx == 0) & W_is_opx_inst; assign W_op_eret = (W_iw_opx == 1) & W_is_opx_inst; assign W_op_roli = (W_iw_opx == 2) & W_is_opx_inst; assign W_op_rol = (W_iw_opx == 3) & W_is_opx_inst; assign W_op_flushp = (W_iw_opx == 4) & W_is_opx_inst; assign W_op_ret = (W_iw_opx == 5) & W_is_opx_inst; assign W_op_nor = (W_iw_opx == 6) & W_is_opx_inst; assign W_op_mulxuu = (W_iw_opx == 7) & W_is_opx_inst; assign W_op_cmpge = (W_iw_opx == 8) & W_is_opx_inst; assign W_op_bret = (W_iw_opx == 9) & W_is_opx_inst; assign W_op_opx_rsv10 = (W_iw_opx == 10) & W_is_opx_inst; assign W_op_ror = (W_iw_opx == 11) & W_is_opx_inst; assign W_op_flushi = (W_iw_opx == 12) & W_is_opx_inst; assign W_op_jmp = (W_iw_opx == 13) & W_is_opx_inst; assign W_op_and = (W_iw_opx == 14) & W_is_opx_inst; assign W_op_opx_rsv15 = (W_iw_opx == 15) & W_is_opx_inst; assign W_op_cmplt = (W_iw_opx == 16) & W_is_opx_inst; assign W_op_opx_rsv17 = (W_iw_opx == 17) & W_is_opx_inst; assign W_op_slli = (W_iw_opx == 18) & W_is_opx_inst; assign W_op_sll = (W_iw_opx == 19) & W_is_opx_inst; assign W_op_wrprs = (W_iw_opx == 20) & W_is_opx_inst; assign W_op_opx_rsv21 = (W_iw_opx == 21) & W_is_opx_inst; assign W_op_or = (W_iw_opx == 22) & W_is_opx_inst; assign W_op_mulxsu = (W_iw_opx == 23) & W_is_opx_inst; assign W_op_cmpne = (W_iw_opx == 24) & W_is_opx_inst; assign W_op_opx_rsv25 = (W_iw_opx == 25) & W_is_opx_inst; assign W_op_srli = (W_iw_opx == 26) & W_is_opx_inst; assign W_op_srl = (W_iw_opx == 27) & W_is_opx_inst; assign W_op_nextpc = (W_iw_opx == 28) & W_is_opx_inst; assign W_op_callr = (W_iw_opx == 29) & W_is_opx_inst; assign W_op_xor = (W_iw_opx == 30) & W_is_opx_inst; assign W_op_mulxss = (W_iw_opx == 31) & W_is_opx_inst; assign W_op_cmpeq = (W_iw_opx == 32) & W_is_opx_inst; assign W_op_opx_rsv33 = (W_iw_opx == 33) & W_is_opx_inst; assign W_op_opx_rsv34 = (W_iw_opx == 34) & W_is_opx_inst; assign W_op_opx_rsv35 = (W_iw_opx == 35) & W_is_opx_inst; assign W_op_divu = (W_iw_opx == 36) & W_is_opx_inst; assign W_op_div = (W_iw_opx == 37) & W_is_opx_inst; assign W_op_rdctl = (W_iw_opx == 38) & W_is_opx_inst; assign W_op_mul = (W_iw_opx == 39) & W_is_opx_inst; assign W_op_cmpgeu = (W_iw_opx == 40) & W_is_opx_inst; assign W_op_initi = (W_iw_opx == 41) & W_is_opx_inst; assign W_op_opx_rsv42 = (W_iw_opx == 42) & W_is_opx_inst; assign W_op_opx_rsv43 = (W_iw_opx == 43) & W_is_opx_inst; assign W_op_opx_rsv44 = (W_iw_opx == 44) & W_is_opx_inst; assign W_op_trap = (W_iw_opx == 45) & W_is_opx_inst; assign W_op_wrctl = (W_iw_opx == 46) & W_is_opx_inst; assign W_op_opx_rsv47 = (W_iw_opx == 47) & W_is_opx_inst; assign W_op_cmpltu = (W_iw_opx == 48) & W_is_opx_inst; assign W_op_add = (W_iw_opx == 49) & W_is_opx_inst; assign W_op_opx_rsv50 = (W_iw_opx == 50) & W_is_opx_inst; assign W_op_opx_rsv51 = (W_iw_opx == 51) & W_is_opx_inst; assign W_op_break = (W_iw_opx == 52) & W_is_opx_inst; assign W_op_hbreak = (W_iw_opx == 53) & W_is_opx_inst; assign W_op_sync = (W_iw_opx == 54) & W_is_opx_inst; assign W_op_opx_rsv55 = (W_iw_opx == 55) & W_is_opx_inst; assign W_op_opx_rsv56 = (W_iw_opx == 56) & W_is_opx_inst; assign W_op_sub = (W_iw_opx == 57) & W_is_opx_inst; assign W_op_srai = (W_iw_opx == 58) & W_is_opx_inst; assign W_op_sra = (W_iw_opx == 59) & W_is_opx_inst; assign W_op_opx_rsv60 = (W_iw_opx == 60) & W_is_opx_inst; assign W_op_intr = (W_iw_opx == 61) & W_is_opx_inst; assign W_op_crst = (W_iw_opx == 62) & W_is_opx_inst; assign W_op_opx_rsv63 = (W_iw_opx == 63) & W_is_opx_inst; assign W_is_opx_inst = W_iw_op == 58; always @(posedge clk or negedge reset_n) begin if (reset_n == 0) A_target_pcb <= 0; else if (A_en) A_target_pcb <= M_target_pcb; end always @(posedge clk or negedge reset_n) begin if (reset_n == 0) A_mem_baddr <= 0; else if (A_en) A_mem_baddr <= M_mem_baddr; end always @(posedge clk or negedge reset_n) begin if (reset_n == 0) W_wr_data_filtered <= 0; else W_wr_data_filtered <= A_wr_data_filtered; end always @(posedge clk or negedge reset_n) begin if (reset_n == 0) W_st_data <= 0; else W_st_data <= A_st_data; end always @(posedge clk or negedge reset_n) begin if (reset_n == 0) W_cmp_result <= 0; else W_cmp_result <= A_cmp_result; end always @(posedge clk or negedge reset_n) begin if (reset_n == 0) W_target_pcb <= 0; else W_target_pcb <= A_target_pcb; end always @(posedge clk or negedge reset_n) begin if (reset_n == 0) W_valid_hbreak <= 0; else W_valid_hbreak <= A_exc_allowed & A_exc_hbreak_pri1; end always @(posedge clk or negedge reset_n) begin if (reset_n == 0) W_valid_crst <= 0; else W_valid_crst <= A_exc_allowed & 0; end always @(posedge clk or negedge reset_n) begin if (reset_n == 0) W_valid_intr <= 0; else W_valid_intr <= A_exc_allowed & A_exc_norm_intr_pri5; end always @(posedge clk or negedge reset_n) begin if (reset_n == 0) W_exc_any_active <= 0; else W_exc_any_active <= A_exc_any_active; end always @(posedge clk or negedge reset_n) begin if (reset_n == 0) W_exc_highest_pri_exc_id <= 0; else W_exc_highest_pri_exc_id <= A_exc_highest_pri_exc_id; end assign A_iw_invalid = A_exc_inst_fetch & A_exc_active_no_break_no_crst; always @(posedge clk or negedge reset_n) begin if (reset_n == 0) W_iw_invalid <= 0; else W_iw_invalid <= A_iw_invalid; end assign test_has_ended = 1'b0; //synthesis translate_off //////////////// SIMULATION-ONLY CONTENTS //Clearing 'X' data bits assign A_wr_data_unfiltered_0_is_x = ^(A_wr_data_unfiltered[0]) === 1'bx; assign A_wr_data_filtered[0] = (A_wr_data_unfiltered_0_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[0]; assign A_wr_data_unfiltered_1_is_x = ^(A_wr_data_unfiltered[1]) === 1'bx; assign A_wr_data_filtered[1] = (A_wr_data_unfiltered_1_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[1]; assign A_wr_data_unfiltered_2_is_x = ^(A_wr_data_unfiltered[2]) === 1'bx; assign A_wr_data_filtered[2] = (A_wr_data_unfiltered_2_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[2]; assign A_wr_data_unfiltered_3_is_x = ^(A_wr_data_unfiltered[3]) === 1'bx; assign A_wr_data_filtered[3] = (A_wr_data_unfiltered_3_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[3]; assign A_wr_data_unfiltered_4_is_x = ^(A_wr_data_unfiltered[4]) === 1'bx; assign A_wr_data_filtered[4] = (A_wr_data_unfiltered_4_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[4]; assign A_wr_data_unfiltered_5_is_x = ^(A_wr_data_unfiltered[5]) === 1'bx; assign A_wr_data_filtered[5] = (A_wr_data_unfiltered_5_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[5]; assign A_wr_data_unfiltered_6_is_x = ^(A_wr_data_unfiltered[6]) === 1'bx; assign A_wr_data_filtered[6] = (A_wr_data_unfiltered_6_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[6]; assign A_wr_data_unfiltered_7_is_x = ^(A_wr_data_unfiltered[7]) === 1'bx; assign A_wr_data_filtered[7] = (A_wr_data_unfiltered_7_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[7]; assign A_wr_data_unfiltered_8_is_x = ^(A_wr_data_unfiltered[8]) === 1'bx; assign A_wr_data_filtered[8] = (A_wr_data_unfiltered_8_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[8]; assign A_wr_data_unfiltered_9_is_x = ^(A_wr_data_unfiltered[9]) === 1'bx; assign A_wr_data_filtered[9] = (A_wr_data_unfiltered_9_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[9]; assign A_wr_data_unfiltered_10_is_x = ^(A_wr_data_unfiltered[10]) === 1'bx; assign A_wr_data_filtered[10] = (A_wr_data_unfiltered_10_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[10]; assign A_wr_data_unfiltered_11_is_x = ^(A_wr_data_unfiltered[11]) === 1'bx; assign A_wr_data_filtered[11] = (A_wr_data_unfiltered_11_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[11]; assign A_wr_data_unfiltered_12_is_x = ^(A_wr_data_unfiltered[12]) === 1'bx; assign A_wr_data_filtered[12] = (A_wr_data_unfiltered_12_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[12]; assign A_wr_data_unfiltered_13_is_x = ^(A_wr_data_unfiltered[13]) === 1'bx; assign A_wr_data_filtered[13] = (A_wr_data_unfiltered_13_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[13]; assign A_wr_data_unfiltered_14_is_x = ^(A_wr_data_unfiltered[14]) === 1'bx; assign A_wr_data_filtered[14] = (A_wr_data_unfiltered_14_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[14]; assign A_wr_data_unfiltered_15_is_x = ^(A_wr_data_unfiltered[15]) === 1'bx; assign A_wr_data_filtered[15] = (A_wr_data_unfiltered_15_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[15]; assign A_wr_data_unfiltered_16_is_x = ^(A_wr_data_unfiltered[16]) === 1'bx; assign A_wr_data_filtered[16] = (A_wr_data_unfiltered_16_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[16]; assign A_wr_data_unfiltered_17_is_x = ^(A_wr_data_unfiltered[17]) === 1'bx; assign A_wr_data_filtered[17] = (A_wr_data_unfiltered_17_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[17]; assign A_wr_data_unfiltered_18_is_x = ^(A_wr_data_unfiltered[18]) === 1'bx; assign A_wr_data_filtered[18] = (A_wr_data_unfiltered_18_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[18]; assign A_wr_data_unfiltered_19_is_x = ^(A_wr_data_unfiltered[19]) === 1'bx; assign A_wr_data_filtered[19] = (A_wr_data_unfiltered_19_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[19]; assign A_wr_data_unfiltered_20_is_x = ^(A_wr_data_unfiltered[20]) === 1'bx; assign A_wr_data_filtered[20] = (A_wr_data_unfiltered_20_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[20]; assign A_wr_data_unfiltered_21_is_x = ^(A_wr_data_unfiltered[21]) === 1'bx; assign A_wr_data_filtered[21] = (A_wr_data_unfiltered_21_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[21]; assign A_wr_data_unfiltered_22_is_x = ^(A_wr_data_unfiltered[22]) === 1'bx; assign A_wr_data_filtered[22] = (A_wr_data_unfiltered_22_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[22]; assign A_wr_data_unfiltered_23_is_x = ^(A_wr_data_unfiltered[23]) === 1'bx; assign A_wr_data_filtered[23] = (A_wr_data_unfiltered_23_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[23]; assign A_wr_data_unfiltered_24_is_x = ^(A_wr_data_unfiltered[24]) === 1'bx; assign A_wr_data_filtered[24] = (A_wr_data_unfiltered_24_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[24]; assign A_wr_data_unfiltered_25_is_x = ^(A_wr_data_unfiltered[25]) === 1'bx; assign A_wr_data_filtered[25] = (A_wr_data_unfiltered_25_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[25]; assign A_wr_data_unfiltered_26_is_x = ^(A_wr_data_unfiltered[26]) === 1'bx; assign A_wr_data_filtered[26] = (A_wr_data_unfiltered_26_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[26]; assign A_wr_data_unfiltered_27_is_x = ^(A_wr_data_unfiltered[27]) === 1'bx; assign A_wr_data_filtered[27] = (A_wr_data_unfiltered_27_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[27]; assign A_wr_data_unfiltered_28_is_x = ^(A_wr_data_unfiltered[28]) === 1'bx; assign A_wr_data_filtered[28] = (A_wr_data_unfiltered_28_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[28]; assign A_wr_data_unfiltered_29_is_x = ^(A_wr_data_unfiltered[29]) === 1'bx; assign A_wr_data_filtered[29] = (A_wr_data_unfiltered_29_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[29]; assign A_wr_data_unfiltered_30_is_x = ^(A_wr_data_unfiltered[30]) === 1'bx; assign A_wr_data_filtered[30] = (A_wr_data_unfiltered_30_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[30]; assign A_wr_data_unfiltered_31_is_x = ^(A_wr_data_unfiltered[31]) === 1'bx; assign A_wr_data_filtered[31] = (A_wr_data_unfiltered_31_is_x & (A_ctrl_ld_non_bypass)) ? 1'b0 : A_wr_data_unfiltered[31]; //Clearing 'X' data bits assign E_add_br_to_taken_history_unfiltered_is_x = ^(E_add_br_to_taken_history_unfiltered) === 1'bx; assign E_add_br_to_taken_history_filtered = E_add_br_to_taken_history_unfiltered_is_x ? 1'b0 : E_add_br_to_taken_history_unfiltered; //Clearing 'X' data bits assign M_bht_wr_en_unfiltered_is_x = ^(M_bht_wr_en_unfiltered) === 1'bx; assign M_bht_wr_en_filtered = M_bht_wr_en_unfiltered_is_x ? 1'b0 : M_bht_wr_en_unfiltered; //Clearing 'X' data bits assign M_bht_wr_data_unfiltered_0_is_x = ^(M_bht_wr_data_unfiltered[0]) === 1'bx; assign M_bht_wr_data_filtered[0] = M_bht_wr_data_unfiltered_0_is_x ? 1'b0 : M_bht_wr_data_unfiltered[0]; assign M_bht_wr_data_unfiltered_1_is_x = ^(M_bht_wr_data_unfiltered[1]) === 1'bx; assign M_bht_wr_data_filtered[1] = M_bht_wr_data_unfiltered_1_is_x ? 1'b0 : M_bht_wr_data_unfiltered[1]; //Clearing 'X' data bits assign M_bht_ptr_unfiltered_0_is_x = ^(M_bht_ptr_unfiltered[0]) === 1'bx; assign M_bht_ptr_filtered[0] = M_bht_ptr_unfiltered_0_is_x ? 1'b0 : M_bht_ptr_unfiltered[0]; assign M_bht_ptr_unfiltered_1_is_x = ^(M_bht_ptr_unfiltered[1]) === 1'bx; assign M_bht_ptr_filtered[1] = M_bht_ptr_unfiltered_1_is_x ? 1'b0 : M_bht_ptr_unfiltered[1]; assign M_bht_ptr_unfiltered_2_is_x = ^(M_bht_ptr_unfiltered[2]) === 1'bx; assign M_bht_ptr_filtered[2] = M_bht_ptr_unfiltered_2_is_x ? 1'b0 : M_bht_ptr_unfiltered[2]; assign M_bht_ptr_unfiltered_3_is_x = ^(M_bht_ptr_unfiltered[3]) === 1'bx; assign M_bht_ptr_filtered[3] = M_bht_ptr_unfiltered_3_is_x ? 1'b0 : M_bht_ptr_unfiltered[3]; assign M_bht_ptr_unfiltered_4_is_x = ^(M_bht_ptr_unfiltered[4]) === 1'bx; assign M_bht_ptr_filtered[4] = M_bht_ptr_unfiltered_4_is_x ? 1'b0 : M_bht_ptr_unfiltered[4]; assign M_bht_ptr_unfiltered_5_is_x = ^(M_bht_ptr_unfiltered[5]) === 1'bx; assign M_bht_ptr_filtered[5] = M_bht_ptr_unfiltered_5_is_x ? 1'b0 : M_bht_ptr_unfiltered[5]; assign M_bht_ptr_unfiltered_6_is_x = ^(M_bht_ptr_unfiltered[6]) === 1'bx; assign M_bht_ptr_filtered[6] = M_bht_ptr_unfiltered_6_is_x ? 1'b0 : M_bht_ptr_unfiltered[6]; assign M_bht_ptr_unfiltered_7_is_x = ^(M_bht_ptr_unfiltered[7]) === 1'bx; assign M_bht_ptr_filtered[7] = M_bht_ptr_unfiltered_7_is_x ? 1'b0 : M_bht_ptr_unfiltered[7]; always @(posedge clk) begin if (reset_n) if (^(W_wr_dst_reg) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/W_wr_dst_reg is 'x'\n", $time); $stop; end end always @(posedge clk or negedge reset_n) begin if (reset_n == 0) begin end else if (W_wr_dst_reg) if (^(W_dst_regnum) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/W_dst_regnum is 'x'\n", $time); $stop; end end always @(posedge clk) begin if (reset_n) if (^(W_valid) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/W_valid is 'x'\n", $time); $stop; end end always @(posedge clk or negedge reset_n) begin if (reset_n == 0) begin end else if (W_valid) if (^(W_pcb) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/W_pcb is 'x'\n", $time); $stop; end end always @(posedge clk or negedge reset_n) begin if (reset_n == 0) begin end else if (W_valid) if (^(W_iw) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/W_iw is 'x'\n", $time); $stop; end end always @(posedge clk) begin if (reset_n) if (^(A_en) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/A_en is 'x'\n", $time); $stop; end end always @(posedge clk) begin if (reset_n) if (^(M_valid) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/M_valid is 'x'\n", $time); $stop; end end always @(posedge clk) begin if (reset_n) if (^(A_valid) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/A_valid is 'x'\n", $time); $stop; end end always @(posedge clk or negedge reset_n) begin if (reset_n == 0) begin end else if (A_valid & A_en & A_wr_dst_reg) if (^(A_wr_data_unfiltered) === 1'bx) begin $write("%0d ns: WARNING: soc_design_niosII_core_cpu_test_bench/A_wr_data_unfiltered is 'x'\n", $time); end end always @(posedge clk) begin if (reset_n) if (^(W_status_reg) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/W_status_reg is 'x'\n", $time); $stop; end end always @(posedge clk) begin if (reset_n) if (^(W_estatus_reg) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/W_estatus_reg is 'x'\n", $time); $stop; end end always @(posedge clk) begin if (reset_n) if (^(W_bstatus_reg) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/W_bstatus_reg is 'x'\n", $time); $stop; end end always @(posedge clk) begin if (reset_n) if (^(W_exception_reg) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/W_exception_reg is 'x'\n", $time); $stop; end end always @(posedge clk) begin if (reset_n) if (^(W_badaddr_reg) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/W_badaddr_reg is 'x'\n", $time); $stop; end end always @(posedge clk) begin if (reset_n) if (^(A_exc_any_active) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/A_exc_any_active is 'x'\n", $time); $stop; end end always @(posedge clk) begin if (reset_n) if (^(i_read) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/i_read is 'x'\n", $time); $stop; end end always @(posedge clk or negedge reset_n) begin if (reset_n == 0) begin end else if (i_read) if (^(i_address) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/i_address is 'x'\n", $time); $stop; end end always @(posedge clk) begin if (reset_n) if (^(d_write) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/d_write is 'x'\n", $time); $stop; end end always @(posedge clk or negedge reset_n) begin if (reset_n == 0) begin end else if (d_write) if (^(d_byteenable) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/d_byteenable is 'x'\n", $time); $stop; end end always @(posedge clk or negedge reset_n) begin if (reset_n == 0) begin end else if (d_write | d_read) if (^(d_address) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/d_address is 'x'\n", $time); $stop; end end always @(posedge clk) begin if (reset_n) if (^(d_read) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/d_read is 'x'\n", $time); $stop; end end always @(posedge clk) begin if (reset_n) if (^(i_readdatavalid) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/i_readdatavalid is 'x'\n", $time); $stop; end end always @(posedge clk) begin if (reset_n) if (^(d_readdatavalid) === 1'bx) begin $write("%0d ns: ERROR: soc_design_niosII_core_cpu_test_bench/d_readdatavalid is 'x'\n", $time); $stop; end end //////////////// END SIMULATION-ONLY CONTENTS //synthesis translate_on //synthesis read_comments_as_HDL on // // assign A_wr_data_filtered = A_wr_data_unfiltered; // // // assign E_add_br_to_taken_history_filtered = E_add_br_to_taken_history_unfiltered; // // // assign M_bht_wr_en_filtered = M_bht_wr_en_unfiltered; // // // assign M_bht_wr_data_filtered = M_bht_wr_data_unfiltered; // // // assign M_bht_ptr_filtered = M_bht_ptr_unfiltered; // //synthesis read_comments_as_HDL off endmodule
//***************************************************************************** // (c) Copyright 2009 - 2013 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: infrastructure.v // /___/ /\ Date Last Modified: $Date: 2011/06/02 08:34:56 $ // \ \ / \ Date Created:Tue Jun 30 2009 // \___\/\___\ // //Device: Virtex-6 //Design Name: DDR3 SDRAM //Purpose: // Clock generation/distribution and reset synchronization //Reference: //Revision History: //***************************************************************************** /****************************************************************************** **$Id: infrastructure.v,v 1.1 2011/06/02 08:34:56 mishra Exp $ **$Date: 2011/06/02 08:34:56 $ **$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/clocking/infrastructure.v,v $ ******************************************************************************/ `timescale 1ps/1ps module mig_7series_v1_9_infrastructure # ( parameter SIMULATION = "FALSE", // Should be TRUE during design simulations and // FALSE during implementations parameter TCQ = 100, // clk->out delay (sim only) parameter CLKIN_PERIOD = 3000, // Memory clock period parameter nCK_PER_CLK = 2, // Fabric clk period:Memory clk period parameter SYSCLK_TYPE = "DIFFERENTIAL", // input clock type // "DIFFERENTIAL","SINGLE_ENDED" parameter UI_EXTRA_CLOCKS = "FALSE", // Generates extra clocks as // 1/2, 1/4 and 1/8 of fabrick clock. // Valid for DDR2/DDR3 AXI interfaces // based on GUI selection parameter CLKFBOUT_MULT = 4, // write PLL VCO multiplier parameter DIVCLK_DIVIDE = 1, // write PLL VCO divisor parameter CLKOUT0_PHASE = 45.0, // VCO output divisor for clkout0 parameter CLKOUT0_DIVIDE = 16, // VCO output divisor for PLL clkout0 parameter CLKOUT1_DIVIDE = 4, // VCO output divisor for PLL clkout1 parameter CLKOUT2_DIVIDE = 64, // VCO output divisor for PLL clkout2 parameter CLKOUT3_DIVIDE = 16, // VCO output divisor for PLL clkout3 parameter MMCM_CLKOUT0_EN = "FALSE", // Enabled (or) Disable MMCM clkout0 parameter MMCM_CLKOUT1_EN = "FALSE", // Enabled (or) Disable MMCM clkout1 parameter MMCM_CLKOUT2_EN = "FALSE", // Enabled (or) Disable MMCM clkout2 parameter MMCM_CLKOUT3_EN = "FALSE", // Enabled (or) Disable MMCM clkout3 parameter MMCM_CLKOUT4_EN = "FALSE", // Enabled (or) Disable MMCM clkout4 parameter MMCM_CLKOUT0_DIVIDE = 1, // VCO output divisor for MMCM clkout0 parameter MMCM_CLKOUT1_DIVIDE = 1, // VCO output divisor for MMCM clkout1 parameter MMCM_CLKOUT2_DIVIDE = 1, // VCO output divisor for MMCM clkout2 parameter MMCM_CLKOUT3_DIVIDE = 1, // VCO output divisor for MMCM clkout3 parameter MMCM_CLKOUT4_DIVIDE = 1, // VCO output divisor for MMCM clkout4 parameter RST_ACT_LOW = 1 ) ( // Clock inputs input mmcm_clk, // System clock diff input // System reset input input sys_rst, // core reset from user application // PLLE2/IDELAYCTRL Lock status input iodelay_ctrl_rdy, // IDELAYCTRL lock status // Clock outputs output clk, // fabric clock freq ; either half rate or quarter rate and is // determined by PLL parameters settings. output mem_refclk, // equal to memory clock output freq_refclk, // freq above 400 MHz: set freq_refclk = mem_refclk // freq below 400 MHz: set freq_refclk = 2* mem_refclk or 4* mem_refclk; // to hard PHY for phaser output sync_pulse, // exactly 1/16 of mem_refclk and the sync pulse is exactly 1 memref_clk wide output auxout_clk, // IO clk used to clock out Aux_Out ports output ui_addn_clk_0, // MMCM out0 clk output ui_addn_clk_1, // MMCM out1 clk output ui_addn_clk_2, // MMCM out2 clk output ui_addn_clk_3, // MMCM out3 clk output ui_addn_clk_4, // MMCM out4 clk output pll_locked, // locked output from PLLE2_ADV output mmcm_locked, // locked output from MMCME2_ADV // Reset outputs output rstdiv0 // Reset CLK and CLKDIV logic (incl I/O), ,output rst_phaser_ref ,input ref_dll_lock ); // # of clock cycles to delay deassertion of reset. Needs to be a fairly // high number not so much for metastability protection, but to give time // for reset (i.e. stable clock cycles) to propagate through all state // machines and to all control signals (i.e. not all control signals have // resets, instead they rely on base state logic being reset, and the effect // of that reset propagating through the logic). Need this because we may not // be getting stable clock cycles while reset asserted (i.e. since reset // depends on DCM lock status) localparam RST_SYNC_NUM = 25; // Round up for clk reset delay to ensure that CLKDIV reset deassertion // occurs at same time or after CLK reset deassertion (still need to // consider route delay - add one or two extra cycles to be sure!) localparam RST_DIV_SYNC_NUM = (RST_SYNC_NUM+1)/2; // Input clock is assumed to be equal to the memory clock frequency // User should change the parameter as necessary if a different input // clock frequency is used localparam real CLKIN1_PERIOD_NS = CLKIN_PERIOD / 1000.0; localparam CLKOUT4_DIVIDE = 2 * CLKOUT1_DIVIDE; localparam integer VCO_PERIOD = (CLKIN1_PERIOD_NS * DIVCLK_DIVIDE * 1000) / CLKFBOUT_MULT; localparam CLKOUT0_PERIOD = VCO_PERIOD * CLKOUT0_DIVIDE; localparam CLKOUT1_PERIOD = VCO_PERIOD * CLKOUT1_DIVIDE; localparam CLKOUT2_PERIOD = VCO_PERIOD * CLKOUT2_DIVIDE; localparam CLKOUT3_PERIOD = VCO_PERIOD * CLKOUT3_DIVIDE; localparam CLKOUT4_PERIOD = VCO_PERIOD * CLKOUT4_DIVIDE; localparam CLKOUT4_PHASE = (SIMULATION == "TRUE") ? 22.5 : 168.75; localparam real CLKOUT3_PERIOD_NS = CLKOUT3_PERIOD / 1000.0; localparam real CLKOUT4_PERIOD_NS = CLKOUT4_PERIOD / 1000.0; //synthesis translate_off initial begin $display("############# Write Clocks PLLE2_ADV Parameters #############\n"); $display("nCK_PER_CLK = %7d", nCK_PER_CLK ); $display("CLK_PERIOD = %7d", CLKIN_PERIOD ); $display("CLKIN1_PERIOD = %7.3f", CLKIN1_PERIOD_NS); $display("DIVCLK_DIVIDE = %7d", DIVCLK_DIVIDE ); $display("CLKFBOUT_MULT = %7d", CLKFBOUT_MULT ); $display("VCO_PERIOD = %7d", VCO_PERIOD ); $display("CLKOUT0_DIVIDE_F = %7d", CLKOUT0_DIVIDE ); $display("CLKOUT1_DIVIDE = %7d", CLKOUT1_DIVIDE ); $display("CLKOUT2_DIVIDE = %7d", CLKOUT2_DIVIDE ); $display("CLKOUT3_DIVIDE = %7d", CLKOUT3_DIVIDE ); $display("CLKOUT0_PERIOD = %7d", CLKOUT0_PERIOD ); $display("CLKOUT1_PERIOD = %7d", CLKOUT1_PERIOD ); $display("CLKOUT2_PERIOD = %7d", CLKOUT2_PERIOD ); $display("CLKOUT3_PERIOD = %7d", CLKOUT3_PERIOD ); $display("CLKOUT4_PERIOD = %7d", CLKOUT4_PERIOD ); $display("############################################################\n"); end //synthesis translate_on wire clk_bufg; wire clk_pll; wire clkfbout_pll; wire mmcm_clkfbout; (* keep = "true", max_fanout = 10 *) wire pll_locked_i /* synthesis syn_maxfan = 10 */; reg [RST_DIV_SYNC_NUM-2:0] rstdiv0_sync_r; wire rst_tmp; (* keep = "true", max_fanout = 10 *) reg rstdiv0_sync_r1 /* synthesis syn_maxfan = 10 */; wire sys_rst_act_hi; wire rst_tmp_phaser_ref; (* keep = "true", max_fanout = 10 *) reg [RST_DIV_SYNC_NUM-1:0] rst_phaser_ref_sync_r /* synthesis syn_maxfan = 10 */; // Instantiation of the MMCM primitive wire clkfbout; wire MMCM_Locked_i; wire mmcm_clkout0; wire mmcm_clkout1; wire mmcm_clkout2; wire mmcm_clkout3; wire mmcm_clkout4; assign sys_rst_act_hi = RST_ACT_LOW ? ~sys_rst: sys_rst; //*************************************************************************** // Assign global clocks: // 2. clk : Half rate / Quarter rate(used for majority of internal logic) //*************************************************************************** assign clk = clk_bufg; assign pll_locked = pll_locked_i & MMCM_Locked_i; assign mmcm_locked = MMCM_Locked_i; //*************************************************************************** // Global base clock generation and distribution //*************************************************************************** //***************************************************************** // NOTES ON CALCULTING PROPER VCO FREQUENCY // 1. VCO frequency = // 1/((DIVCLK_DIVIDE * CLKIN_PERIOD)/(CLKFBOUT_MULT * nCK_PER_CLK)) // 2. VCO frequency must be in the range [TBD, TBD] //***************************************************************** PLLE2_ADV # ( .BANDWIDTH ("OPTIMIZED"), .COMPENSATION ("INTERNAL"), .STARTUP_WAIT ("FALSE"), .CLKOUT0_DIVIDE (CLKOUT0_DIVIDE), // 4 freq_ref .CLKOUT1_DIVIDE (CLKOUT1_DIVIDE), // 4 mem_ref .CLKOUT2_DIVIDE (CLKOUT2_DIVIDE), // 16 sync .CLKOUT3_DIVIDE (CLKOUT3_DIVIDE), // 16 sysclk .CLKOUT4_DIVIDE (CLKOUT4_DIVIDE), .CLKOUT5_DIVIDE (), .DIVCLK_DIVIDE (DIVCLK_DIVIDE), .CLKFBOUT_MULT (CLKFBOUT_MULT), .CLKFBOUT_PHASE (0.000), .CLKIN1_PERIOD (CLKIN1_PERIOD_NS), .CLKIN2_PERIOD (), .CLKOUT0_DUTY_CYCLE (0.500), .CLKOUT0_PHASE (CLKOUT0_PHASE), .CLKOUT1_DUTY_CYCLE (0.500), .CLKOUT1_PHASE (0.000), .CLKOUT2_DUTY_CYCLE (1.0/16.0), .CLKOUT2_PHASE (9.84375), // PHASE shift is required for sync pulse generation. .CLKOUT3_DUTY_CYCLE (0.500), .CLKOUT3_PHASE (0.000), .CLKOUT4_DUTY_CYCLE (0.500), .CLKOUT4_PHASE (CLKOUT4_PHASE), .CLKOUT5_DUTY_CYCLE (0.500), .CLKOUT5_PHASE (0.000), .REF_JITTER1 (0.010), .REF_JITTER2 (0.010) ) plle2_i ( .CLKFBOUT (pll_clkfbout), .CLKOUT0 (freq_refclk), .CLKOUT1 (mem_refclk), .CLKOUT2 (sync_pulse), // always 1/16 of mem_ref_clk .CLKOUT3 (pll_clk3), .CLKOUT4 (auxout_clk_i), .CLKOUT5 (), .DO (), .DRDY (), .LOCKED (pll_locked_i), .CLKFBIN (pll_clkfbout), .CLKIN1 (mmcm_clk), .CLKIN2 (), .CLKINSEL (1'b1), .DADDR (7'b0), .DCLK (1'b0), .DEN (1'b0), .DI (16'b0), .DWE (1'b0), .PWRDWN (1'b0), .RST ( sys_rst_act_hi) ); BUFH u_bufh_auxout_clk ( .O (auxout_clk), .I (auxout_clk_i) ); BUFG u_bufg_clkdiv0 ( .O (clk_bufg), .I (clk_pll_i) ); localparam integer MMCM_VCO_MIN_FREQ = 600; localparam integer MMCM_VCO_MAX_FREQ = 1200; // This is the maximum VCO frequency for a -1 part localparam real MMCM_VCO_MIN_PERIOD = 1000000.0/MMCM_VCO_MAX_FREQ; localparam real MMCM_VCO_MAX_PERIOD = 1000000.0/MMCM_VCO_MIN_FREQ; localparam real MMCM_MULT_F_MID = CLKOUT3_PERIOD/(MMCM_VCO_MAX_PERIOD*0.75); localparam real MMCM_EXPECTED_PERIOD = CLKOUT3_PERIOD / MMCM_MULT_F_MID; localparam real MMCM_MULT_F = ((MMCM_EXPECTED_PERIOD > MMCM_VCO_MAX_PERIOD) ? MMCM_MULT_F_MID + 1.0 : MMCM_MULT_F_MID); localparam real MMCM_VCO_FREQ = MMCM_MULT_F / (1 * CLKOUT3_PERIOD_NS); localparam real MMCM_VCO_PERIOD = (CLKOUT3_PERIOD_NS * 1000) / MMCM_MULT_F; //synthesis translate_off initial begin $display("############# MMCME2_ADV Parameters #############\n"); $display("MMCM_VCO_MIN_PERIOD = %7.3f", MMCM_VCO_MIN_PERIOD); $display("MMCM_VCO_MAX_PERIOD = %7.3f", MMCM_VCO_MAX_PERIOD); $display("MMCM_MULT_F_MID = %7.3f", MMCM_MULT_F_MID); $display("MMCM_EXPECTED_PERIOD = %7.3f", MMCM_EXPECTED_PERIOD); $display("MMCM_MULT_F = %7.3f", MMCM_MULT_F); $display("CLKOUT3_PERIOD_NS = %7.3f", CLKOUT3_PERIOD_NS); $display("MMCM_VCO_FREQ (MHz) = %7.3f", MMCM_VCO_FREQ*1000.0); $display("MMCM_VCO_PERIOD = %7.3f", MMCM_VCO_PERIOD); $display("#################################################\n"); end //synthesis translate_on generate if (UI_EXTRA_CLOCKS == "TRUE") begin: gen_ui_extra_clocks localparam MMCM_CLKOUT0_DIVIDE_CAL = (MMCM_CLKOUT0_EN == "TRUE") ? MMCM_CLKOUT0_DIVIDE : MMCM_MULT_F; localparam MMCM_CLKOUT1_DIVIDE_CAL = (MMCM_CLKOUT1_EN == "TRUE") ? MMCM_CLKOUT1_DIVIDE : MMCM_MULT_F; localparam MMCM_CLKOUT2_DIVIDE_CAL = (MMCM_CLKOUT2_EN == "TRUE") ? MMCM_CLKOUT2_DIVIDE : MMCM_MULT_F; localparam MMCM_CLKOUT3_DIVIDE_CAL = (MMCM_CLKOUT3_EN == "TRUE") ? MMCM_CLKOUT3_DIVIDE : MMCM_MULT_F; localparam MMCM_CLKOUT4_DIVIDE_CAL = (MMCM_CLKOUT4_EN == "TRUE") ? MMCM_CLKOUT4_DIVIDE : MMCM_MULT_F; MMCME2_ADV #(.BANDWIDTH ("HIGH"), .CLKOUT4_CASCADE ("FALSE"), .COMPENSATION ("BUF_IN"), .STARTUP_WAIT ("FALSE"), .DIVCLK_DIVIDE (1), .CLKFBOUT_MULT_F (MMCM_MULT_F), .CLKFBOUT_PHASE (0.000), .CLKFBOUT_USE_FINE_PS ("FALSE"), .CLKOUT0_DIVIDE_F (MMCM_CLKOUT0_DIVIDE_CAL), .CLKOUT0_PHASE (0.000), .CLKOUT0_DUTY_CYCLE (0.500), .CLKOUT0_USE_FINE_PS ("FALSE"), .CLKOUT1_DIVIDE (MMCM_CLKOUT1_DIVIDE_CAL), .CLKOUT1_PHASE (0.000), .CLKOUT1_DUTY_CYCLE (0.500), .CLKOUT1_USE_FINE_PS ("FALSE"), .CLKOUT2_DIVIDE (MMCM_CLKOUT2_DIVIDE_CAL), .CLKOUT2_PHASE (0.000), .CLKOUT2_DUTY_CYCLE (0.500), .CLKOUT2_USE_FINE_PS ("FALSE"), .CLKOUT3_DIVIDE (MMCM_CLKOUT3_DIVIDE_CAL), .CLKOUT3_PHASE (0.000), .CLKOUT3_DUTY_CYCLE (0.500), .CLKOUT3_USE_FINE_PS ("FALSE"), .CLKOUT4_DIVIDE (MMCM_CLKOUT4_DIVIDE_CAL), .CLKOUT4_PHASE (0.000), .CLKOUT4_DUTY_CYCLE (0.500), .CLKOUT4_USE_FINE_PS ("FALSE"), .CLKIN1_PERIOD (CLKOUT3_PERIOD_NS), .REF_JITTER1 (0.000)) mmcm_i // Output clocks (.CLKFBOUT (clk_pll_i), .CLKFBOUTB (), .CLKOUT0 (mmcm_clkout0), .CLKOUT0B (), .CLKOUT1 (mmcm_clkout1), .CLKOUT1B (), .CLKOUT2 (mmcm_clkout2), .CLKOUT2B (), .CLKOUT3 (mmcm_clkout3), .CLKOUT3B (), .CLKOUT4 (mmcm_clkout4), .CLKOUT5 (), .CLKOUT6 (), // Input clock control .CLKFBIN (clk_bufg), // From BUFH network .CLKIN1 (pll_clk3), // From PLL .CLKIN2 (1'b0), // Tied to always select the primary input clock .CLKINSEL (1'b1), // Ports for dynamic reconfiguration .DADDR (7'h0), .DCLK (1'b0), .DEN (1'b0), .DI (16'h0), .DO (), .DRDY (), .DWE (1'b0), // Ports for dynamic phase shift .PSCLK (1'b0), .PSEN (1'b0), .PSINCDEC (1'b0), .PSDONE (), // Other control and status signals .LOCKED (MMCM_Locked_i), .CLKINSTOPPED (), .CLKFBSTOPPED (), .PWRDWN (1'b0), .RST (~pll_locked_i)); BUFG u_bufg_ui_addn_clk_0 ( .O (ui_addn_clk_0), .I (mmcm_clkout0) ); BUFG u_bufg_ui_addn_clk_1 ( .O (ui_addn_clk_1), .I (mmcm_clkout1) ); BUFG u_bufg_ui_addn_clk_2 ( .O (ui_addn_clk_2), .I (mmcm_clkout2) ); BUFG u_bufg_ui_addn_clk_3 ( .O (ui_addn_clk_3), .I (mmcm_clkout3) ); BUFG u_bufg_ui_addn_clk_4 ( .O (ui_addn_clk_4), .I (mmcm_clkout4) ); end else begin: gen_mmcm MMCME2_ADV #(.BANDWIDTH ("HIGH"), .CLKOUT4_CASCADE ("FALSE"), .COMPENSATION ("BUF_IN"), .STARTUP_WAIT ("FALSE"), .DIVCLK_DIVIDE (1), .CLKFBOUT_MULT_F (MMCM_MULT_F), .CLKFBOUT_PHASE (0.000), .CLKFBOUT_USE_FINE_PS ("FALSE"), .CLKOUT0_DIVIDE_F (MMCM_MULT_F), .CLKOUT0_PHASE (0.000), .CLKOUT0_DUTY_CYCLE (0.500), .CLKOUT0_USE_FINE_PS ("FALSE"), .CLKOUT1_DIVIDE (), .CLKOUT1_PHASE (0.000), .CLKOUT1_DUTY_CYCLE (0.500), .CLKOUT1_USE_FINE_PS ("FALSE"), .CLKIN1_PERIOD (CLKOUT3_PERIOD_NS), .REF_JITTER1 (0.000)) mmcm_i // Output clocks (.CLKFBOUT (clk_pll_i), .CLKFBOUTB (), .CLKOUT0 (), .CLKOUT0B (), .CLKOUT1 (), .CLKOUT1B (), .CLKOUT2 (), .CLKOUT2B (), .CLKOUT3 (), .CLKOUT3B (), .CLKOUT4 (), .CLKOUT5 (), .CLKOUT6 (), // Input clock control .CLKFBIN (clk_bufg), // From BUFH network .CLKIN1 (pll_clk3), // From PLL .CLKIN2 (1'b0), // Tied to always select the primary input clock .CLKINSEL (1'b1), // Ports for dynamic reconfiguration .DADDR (7'h0), .DCLK (1'b0), .DEN (1'b0), .DI (16'h0), .DO (), .DRDY (), .DWE (1'b0), // Ports for dynamic phase shift .PSCLK (1'b0), .PSEN (1'b0), .PSINCDEC (1'b0), .PSDONE (), // Other control and status signals .LOCKED (MMCM_Locked_i), .CLKINSTOPPED (), .CLKFBSTOPPED (), .PWRDWN (1'b0), .RST (~pll_locked_i)); end endgenerate //*************************************************************************** // RESET SYNCHRONIZATION DESCRIPTION: // Various resets are generated to ensure that: // 1. All resets are synchronously deasserted with respect to the clock // domain they are interfacing to. There are several different clock // domains - each one will receive a synchronized reset. // 2. The reset deassertion order starts with deassertion of SYS_RST, // followed by deassertion of resets for various parts of the design // (see "RESET ORDER" below) based on the lock status of PLLE2s. // RESET ORDER: // 1. User deasserts SYS_RST // 2. Reset PLLE2 and IDELAYCTRL // 3. Wait for PLLE2 and IDELAYCTRL to lock // 4. Release reset for all I/O primitives and internal logic // OTHER NOTES: // 1. Asynchronously assert reset. This way we can assert reset even if // there is no clock (needed for things like 3-stating output buffers // to prevent initial bus contention). Reset deassertion is synchronous. //*************************************************************************** //***************************************************************** // CLKDIV logic reset //***************************************************************** // Wait for PLLE2 and IDELAYCTRL to lock before releasing reset // current O,25.0 unisim phaser_ref never locks. Need to find out why . assign rst_tmp = sys_rst_act_hi | ~iodelay_ctrl_rdy | ~ref_dll_lock | ~MMCM_Locked_i; always @(posedge clk_bufg or posedge rst_tmp) begin if (rst_tmp) begin rstdiv0_sync_r <= #TCQ {RST_DIV_SYNC_NUM-1{1'b1}}; rstdiv0_sync_r1 <= #TCQ 1'b1 ; end else begin rstdiv0_sync_r <= #TCQ rstdiv0_sync_r << 1; rstdiv0_sync_r1 <= #TCQ rstdiv0_sync_r[RST_DIV_SYNC_NUM-2]; end end assign rstdiv0 = rstdiv0_sync_r1 ; assign rst_tmp_phaser_ref = sys_rst_act_hi | ~pll_locked_i | ~iodelay_ctrl_rdy; always @(posedge clk_bufg or posedge rst_tmp_phaser_ref) if (rst_tmp_phaser_ref) rst_phaser_ref_sync_r <= #TCQ {RST_DIV_SYNC_NUM{1'b1}}; else rst_phaser_ref_sync_r <= #TCQ rst_phaser_ref_sync_r << 1; assign rst_phaser_ref = rst_phaser_ref_sync_r[RST_DIV_SYNC_NUM-1]; endmodule
//***************************************************************************** // (c) Copyright 2009 - 2013 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: infrastructure.v // /___/ /\ Date Last Modified: $Date: 2011/06/02 08:34:56 $ // \ \ / \ Date Created:Tue Jun 30 2009 // \___\/\___\ // //Device: Virtex-6 //Design Name: DDR3 SDRAM //Purpose: // Clock generation/distribution and reset synchronization //Reference: //Revision History: //***************************************************************************** /****************************************************************************** **$Id: infrastructure.v,v 1.1 2011/06/02 08:34:56 mishra Exp $ **$Date: 2011/06/02 08:34:56 $ **$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/clocking/infrastructure.v,v $ ******************************************************************************/ `timescale 1ps/1ps module mig_7series_v1_9_infrastructure # ( parameter SIMULATION = "FALSE", // Should be TRUE during design simulations and // FALSE during implementations parameter TCQ = 100, // clk->out delay (sim only) parameter CLKIN_PERIOD = 3000, // Memory clock period parameter nCK_PER_CLK = 2, // Fabric clk period:Memory clk period parameter SYSCLK_TYPE = "DIFFERENTIAL", // input clock type // "DIFFERENTIAL","SINGLE_ENDED" parameter UI_EXTRA_CLOCKS = "FALSE", // Generates extra clocks as // 1/2, 1/4 and 1/8 of fabrick clock. // Valid for DDR2/DDR3 AXI interfaces // based on GUI selection parameter CLKFBOUT_MULT = 4, // write PLL VCO multiplier parameter DIVCLK_DIVIDE = 1, // write PLL VCO divisor parameter CLKOUT0_PHASE = 45.0, // VCO output divisor for clkout0 parameter CLKOUT0_DIVIDE = 16, // VCO output divisor for PLL clkout0 parameter CLKOUT1_DIVIDE = 4, // VCO output divisor for PLL clkout1 parameter CLKOUT2_DIVIDE = 64, // VCO output divisor for PLL clkout2 parameter CLKOUT3_DIVIDE = 16, // VCO output divisor for PLL clkout3 parameter MMCM_CLKOUT0_EN = "FALSE", // Enabled (or) Disable MMCM clkout0 parameter MMCM_CLKOUT1_EN = "FALSE", // Enabled (or) Disable MMCM clkout1 parameter MMCM_CLKOUT2_EN = "FALSE", // Enabled (or) Disable MMCM clkout2 parameter MMCM_CLKOUT3_EN = "FALSE", // Enabled (or) Disable MMCM clkout3 parameter MMCM_CLKOUT4_EN = "FALSE", // Enabled (or) Disable MMCM clkout4 parameter MMCM_CLKOUT0_DIVIDE = 1, // VCO output divisor for MMCM clkout0 parameter MMCM_CLKOUT1_DIVIDE = 1, // VCO output divisor for MMCM clkout1 parameter MMCM_CLKOUT2_DIVIDE = 1, // VCO output divisor for MMCM clkout2 parameter MMCM_CLKOUT3_DIVIDE = 1, // VCO output divisor for MMCM clkout3 parameter MMCM_CLKOUT4_DIVIDE = 1, // VCO output divisor for MMCM clkout4 parameter RST_ACT_LOW = 1 ) ( // Clock inputs input mmcm_clk, // System clock diff input // System reset input input sys_rst, // core reset from user application // PLLE2/IDELAYCTRL Lock status input iodelay_ctrl_rdy, // IDELAYCTRL lock status // Clock outputs output clk, // fabric clock freq ; either half rate or quarter rate and is // determined by PLL parameters settings. output mem_refclk, // equal to memory clock output freq_refclk, // freq above 400 MHz: set freq_refclk = mem_refclk // freq below 400 MHz: set freq_refclk = 2* mem_refclk or 4* mem_refclk; // to hard PHY for phaser output sync_pulse, // exactly 1/16 of mem_refclk and the sync pulse is exactly 1 memref_clk wide output auxout_clk, // IO clk used to clock out Aux_Out ports output ui_addn_clk_0, // MMCM out0 clk output ui_addn_clk_1, // MMCM out1 clk output ui_addn_clk_2, // MMCM out2 clk output ui_addn_clk_3, // MMCM out3 clk output ui_addn_clk_4, // MMCM out4 clk output pll_locked, // locked output from PLLE2_ADV output mmcm_locked, // locked output from MMCME2_ADV // Reset outputs output rstdiv0 // Reset CLK and CLKDIV logic (incl I/O), ,output rst_phaser_ref ,input ref_dll_lock ); // # of clock cycles to delay deassertion of reset. Needs to be a fairly // high number not so much for metastability protection, but to give time // for reset (i.e. stable clock cycles) to propagate through all state // machines and to all control signals (i.e. not all control signals have // resets, instead they rely on base state logic being reset, and the effect // of that reset propagating through the logic). Need this because we may not // be getting stable clock cycles while reset asserted (i.e. since reset // depends on DCM lock status) localparam RST_SYNC_NUM = 25; // Round up for clk reset delay to ensure that CLKDIV reset deassertion // occurs at same time or after CLK reset deassertion (still need to // consider route delay - add one or two extra cycles to be sure!) localparam RST_DIV_SYNC_NUM = (RST_SYNC_NUM+1)/2; // Input clock is assumed to be equal to the memory clock frequency // User should change the parameter as necessary if a different input // clock frequency is used localparam real CLKIN1_PERIOD_NS = CLKIN_PERIOD / 1000.0; localparam CLKOUT4_DIVIDE = 2 * CLKOUT1_DIVIDE; localparam integer VCO_PERIOD = (CLKIN1_PERIOD_NS * DIVCLK_DIVIDE * 1000) / CLKFBOUT_MULT; localparam CLKOUT0_PERIOD = VCO_PERIOD * CLKOUT0_DIVIDE; localparam CLKOUT1_PERIOD = VCO_PERIOD * CLKOUT1_DIVIDE; localparam CLKOUT2_PERIOD = VCO_PERIOD * CLKOUT2_DIVIDE; localparam CLKOUT3_PERIOD = VCO_PERIOD * CLKOUT3_DIVIDE; localparam CLKOUT4_PERIOD = VCO_PERIOD * CLKOUT4_DIVIDE; localparam CLKOUT4_PHASE = (SIMULATION == "TRUE") ? 22.5 : 168.75; localparam real CLKOUT3_PERIOD_NS = CLKOUT3_PERIOD / 1000.0; localparam real CLKOUT4_PERIOD_NS = CLKOUT4_PERIOD / 1000.0; //synthesis translate_off initial begin $display("############# Write Clocks PLLE2_ADV Parameters #############\n"); $display("nCK_PER_CLK = %7d", nCK_PER_CLK ); $display("CLK_PERIOD = %7d", CLKIN_PERIOD ); $display("CLKIN1_PERIOD = %7.3f", CLKIN1_PERIOD_NS); $display("DIVCLK_DIVIDE = %7d", DIVCLK_DIVIDE ); $display("CLKFBOUT_MULT = %7d", CLKFBOUT_MULT ); $display("VCO_PERIOD = %7d", VCO_PERIOD ); $display("CLKOUT0_DIVIDE_F = %7d", CLKOUT0_DIVIDE ); $display("CLKOUT1_DIVIDE = %7d", CLKOUT1_DIVIDE ); $display("CLKOUT2_DIVIDE = %7d", CLKOUT2_DIVIDE ); $display("CLKOUT3_DIVIDE = %7d", CLKOUT3_DIVIDE ); $display("CLKOUT0_PERIOD = %7d", CLKOUT0_PERIOD ); $display("CLKOUT1_PERIOD = %7d", CLKOUT1_PERIOD ); $display("CLKOUT2_PERIOD = %7d", CLKOUT2_PERIOD ); $display("CLKOUT3_PERIOD = %7d", CLKOUT3_PERIOD ); $display("CLKOUT4_PERIOD = %7d", CLKOUT4_PERIOD ); $display("############################################################\n"); end //synthesis translate_on wire clk_bufg; wire clk_pll; wire clkfbout_pll; wire mmcm_clkfbout; (* keep = "true", max_fanout = 10 *) wire pll_locked_i /* synthesis syn_maxfan = 10 */; reg [RST_DIV_SYNC_NUM-2:0] rstdiv0_sync_r; wire rst_tmp; (* keep = "true", max_fanout = 10 *) reg rstdiv0_sync_r1 /* synthesis syn_maxfan = 10 */; wire sys_rst_act_hi; wire rst_tmp_phaser_ref; (* keep = "true", max_fanout = 10 *) reg [RST_DIV_SYNC_NUM-1:0] rst_phaser_ref_sync_r /* synthesis syn_maxfan = 10 */; // Instantiation of the MMCM primitive wire clkfbout; wire MMCM_Locked_i; wire mmcm_clkout0; wire mmcm_clkout1; wire mmcm_clkout2; wire mmcm_clkout3; wire mmcm_clkout4; assign sys_rst_act_hi = RST_ACT_LOW ? ~sys_rst: sys_rst; //*************************************************************************** // Assign global clocks: // 2. clk : Half rate / Quarter rate(used for majority of internal logic) //*************************************************************************** assign clk = clk_bufg; assign pll_locked = pll_locked_i & MMCM_Locked_i; assign mmcm_locked = MMCM_Locked_i; //*************************************************************************** // Global base clock generation and distribution //*************************************************************************** //***************************************************************** // NOTES ON CALCULTING PROPER VCO FREQUENCY // 1. VCO frequency = // 1/((DIVCLK_DIVIDE * CLKIN_PERIOD)/(CLKFBOUT_MULT * nCK_PER_CLK)) // 2. VCO frequency must be in the range [TBD, TBD] //***************************************************************** PLLE2_ADV # ( .BANDWIDTH ("OPTIMIZED"), .COMPENSATION ("INTERNAL"), .STARTUP_WAIT ("FALSE"), .CLKOUT0_DIVIDE (CLKOUT0_DIVIDE), // 4 freq_ref .CLKOUT1_DIVIDE (CLKOUT1_DIVIDE), // 4 mem_ref .CLKOUT2_DIVIDE (CLKOUT2_DIVIDE), // 16 sync .CLKOUT3_DIVIDE (CLKOUT3_DIVIDE), // 16 sysclk .CLKOUT4_DIVIDE (CLKOUT4_DIVIDE), .CLKOUT5_DIVIDE (), .DIVCLK_DIVIDE (DIVCLK_DIVIDE), .CLKFBOUT_MULT (CLKFBOUT_MULT), .CLKFBOUT_PHASE (0.000), .CLKIN1_PERIOD (CLKIN1_PERIOD_NS), .CLKIN2_PERIOD (), .CLKOUT0_DUTY_CYCLE (0.500), .CLKOUT0_PHASE (CLKOUT0_PHASE), .CLKOUT1_DUTY_CYCLE (0.500), .CLKOUT1_PHASE (0.000), .CLKOUT2_DUTY_CYCLE (1.0/16.0), .CLKOUT2_PHASE (9.84375), // PHASE shift is required for sync pulse generation. .CLKOUT3_DUTY_CYCLE (0.500), .CLKOUT3_PHASE (0.000), .CLKOUT4_DUTY_CYCLE (0.500), .CLKOUT4_PHASE (CLKOUT4_PHASE), .CLKOUT5_DUTY_CYCLE (0.500), .CLKOUT5_PHASE (0.000), .REF_JITTER1 (0.010), .REF_JITTER2 (0.010) ) plle2_i ( .CLKFBOUT (pll_clkfbout), .CLKOUT0 (freq_refclk), .CLKOUT1 (mem_refclk), .CLKOUT2 (sync_pulse), // always 1/16 of mem_ref_clk .CLKOUT3 (pll_clk3), .CLKOUT4 (auxout_clk_i), .CLKOUT5 (), .DO (), .DRDY (), .LOCKED (pll_locked_i), .CLKFBIN (pll_clkfbout), .CLKIN1 (mmcm_clk), .CLKIN2 (), .CLKINSEL (1'b1), .DADDR (7'b0), .DCLK (1'b0), .DEN (1'b0), .DI (16'b0), .DWE (1'b0), .PWRDWN (1'b0), .RST ( sys_rst_act_hi) ); BUFH u_bufh_auxout_clk ( .O (auxout_clk), .I (auxout_clk_i) ); BUFG u_bufg_clkdiv0 ( .O (clk_bufg), .I (clk_pll_i) ); localparam integer MMCM_VCO_MIN_FREQ = 600; localparam integer MMCM_VCO_MAX_FREQ = 1200; // This is the maximum VCO frequency for a -1 part localparam real MMCM_VCO_MIN_PERIOD = 1000000.0/MMCM_VCO_MAX_FREQ; localparam real MMCM_VCO_MAX_PERIOD = 1000000.0/MMCM_VCO_MIN_FREQ; localparam real MMCM_MULT_F_MID = CLKOUT3_PERIOD/(MMCM_VCO_MAX_PERIOD*0.75); localparam real MMCM_EXPECTED_PERIOD = CLKOUT3_PERIOD / MMCM_MULT_F_MID; localparam real MMCM_MULT_F = ((MMCM_EXPECTED_PERIOD > MMCM_VCO_MAX_PERIOD) ? MMCM_MULT_F_MID + 1.0 : MMCM_MULT_F_MID); localparam real MMCM_VCO_FREQ = MMCM_MULT_F / (1 * CLKOUT3_PERIOD_NS); localparam real MMCM_VCO_PERIOD = (CLKOUT3_PERIOD_NS * 1000) / MMCM_MULT_F; //synthesis translate_off initial begin $display("############# MMCME2_ADV Parameters #############\n"); $display("MMCM_VCO_MIN_PERIOD = %7.3f", MMCM_VCO_MIN_PERIOD); $display("MMCM_VCO_MAX_PERIOD = %7.3f", MMCM_VCO_MAX_PERIOD); $display("MMCM_MULT_F_MID = %7.3f", MMCM_MULT_F_MID); $display("MMCM_EXPECTED_PERIOD = %7.3f", MMCM_EXPECTED_PERIOD); $display("MMCM_MULT_F = %7.3f", MMCM_MULT_F); $display("CLKOUT3_PERIOD_NS = %7.3f", CLKOUT3_PERIOD_NS); $display("MMCM_VCO_FREQ (MHz) = %7.3f", MMCM_VCO_FREQ*1000.0); $display("MMCM_VCO_PERIOD = %7.3f", MMCM_VCO_PERIOD); $display("#################################################\n"); end //synthesis translate_on generate if (UI_EXTRA_CLOCKS == "TRUE") begin: gen_ui_extra_clocks localparam MMCM_CLKOUT0_DIVIDE_CAL = (MMCM_CLKOUT0_EN == "TRUE") ? MMCM_CLKOUT0_DIVIDE : MMCM_MULT_F; localparam MMCM_CLKOUT1_DIVIDE_CAL = (MMCM_CLKOUT1_EN == "TRUE") ? MMCM_CLKOUT1_DIVIDE : MMCM_MULT_F; localparam MMCM_CLKOUT2_DIVIDE_CAL = (MMCM_CLKOUT2_EN == "TRUE") ? MMCM_CLKOUT2_DIVIDE : MMCM_MULT_F; localparam MMCM_CLKOUT3_DIVIDE_CAL = (MMCM_CLKOUT3_EN == "TRUE") ? MMCM_CLKOUT3_DIVIDE : MMCM_MULT_F; localparam MMCM_CLKOUT4_DIVIDE_CAL = (MMCM_CLKOUT4_EN == "TRUE") ? MMCM_CLKOUT4_DIVIDE : MMCM_MULT_F; MMCME2_ADV #(.BANDWIDTH ("HIGH"), .CLKOUT4_CASCADE ("FALSE"), .COMPENSATION ("BUF_IN"), .STARTUP_WAIT ("FALSE"), .DIVCLK_DIVIDE (1), .CLKFBOUT_MULT_F (MMCM_MULT_F), .CLKFBOUT_PHASE (0.000), .CLKFBOUT_USE_FINE_PS ("FALSE"), .CLKOUT0_DIVIDE_F (MMCM_CLKOUT0_DIVIDE_CAL), .CLKOUT0_PHASE (0.000), .CLKOUT0_DUTY_CYCLE (0.500), .CLKOUT0_USE_FINE_PS ("FALSE"), .CLKOUT1_DIVIDE (MMCM_CLKOUT1_DIVIDE_CAL), .CLKOUT1_PHASE (0.000), .CLKOUT1_DUTY_CYCLE (0.500), .CLKOUT1_USE_FINE_PS ("FALSE"), .CLKOUT2_DIVIDE (MMCM_CLKOUT2_DIVIDE_CAL), .CLKOUT2_PHASE (0.000), .CLKOUT2_DUTY_CYCLE (0.500), .CLKOUT2_USE_FINE_PS ("FALSE"), .CLKOUT3_DIVIDE (MMCM_CLKOUT3_DIVIDE_CAL), .CLKOUT3_PHASE (0.000), .CLKOUT3_DUTY_CYCLE (0.500), .CLKOUT3_USE_FINE_PS ("FALSE"), .CLKOUT4_DIVIDE (MMCM_CLKOUT4_DIVIDE_CAL), .CLKOUT4_PHASE (0.000), .CLKOUT4_DUTY_CYCLE (0.500), .CLKOUT4_USE_FINE_PS ("FALSE"), .CLKIN1_PERIOD (CLKOUT3_PERIOD_NS), .REF_JITTER1 (0.000)) mmcm_i // Output clocks (.CLKFBOUT (clk_pll_i), .CLKFBOUTB (), .CLKOUT0 (mmcm_clkout0), .CLKOUT0B (), .CLKOUT1 (mmcm_clkout1), .CLKOUT1B (), .CLKOUT2 (mmcm_clkout2), .CLKOUT2B (), .CLKOUT3 (mmcm_clkout3), .CLKOUT3B (), .CLKOUT4 (mmcm_clkout4), .CLKOUT5 (), .CLKOUT6 (), // Input clock control .CLKFBIN (clk_bufg), // From BUFH network .CLKIN1 (pll_clk3), // From PLL .CLKIN2 (1'b0), // Tied to always select the primary input clock .CLKINSEL (1'b1), // Ports for dynamic reconfiguration .DADDR (7'h0), .DCLK (1'b0), .DEN (1'b0), .DI (16'h0), .DO (), .DRDY (), .DWE (1'b0), // Ports for dynamic phase shift .PSCLK (1'b0), .PSEN (1'b0), .PSINCDEC (1'b0), .PSDONE (), // Other control and status signals .LOCKED (MMCM_Locked_i), .CLKINSTOPPED (), .CLKFBSTOPPED (), .PWRDWN (1'b0), .RST (~pll_locked_i)); BUFG u_bufg_ui_addn_clk_0 ( .O (ui_addn_clk_0), .I (mmcm_clkout0) ); BUFG u_bufg_ui_addn_clk_1 ( .O (ui_addn_clk_1), .I (mmcm_clkout1) ); BUFG u_bufg_ui_addn_clk_2 ( .O (ui_addn_clk_2), .I (mmcm_clkout2) ); BUFG u_bufg_ui_addn_clk_3 ( .O (ui_addn_clk_3), .I (mmcm_clkout3) ); BUFG u_bufg_ui_addn_clk_4 ( .O (ui_addn_clk_4), .I (mmcm_clkout4) ); end else begin: gen_mmcm MMCME2_ADV #(.BANDWIDTH ("HIGH"), .CLKOUT4_CASCADE ("FALSE"), .COMPENSATION ("BUF_IN"), .STARTUP_WAIT ("FALSE"), .DIVCLK_DIVIDE (1), .CLKFBOUT_MULT_F (MMCM_MULT_F), .CLKFBOUT_PHASE (0.000), .CLKFBOUT_USE_FINE_PS ("FALSE"), .CLKOUT0_DIVIDE_F (MMCM_MULT_F), .CLKOUT0_PHASE (0.000), .CLKOUT0_DUTY_CYCLE (0.500), .CLKOUT0_USE_FINE_PS ("FALSE"), .CLKOUT1_DIVIDE (), .CLKOUT1_PHASE (0.000), .CLKOUT1_DUTY_CYCLE (0.500), .CLKOUT1_USE_FINE_PS ("FALSE"), .CLKIN1_PERIOD (CLKOUT3_PERIOD_NS), .REF_JITTER1 (0.000)) mmcm_i // Output clocks (.CLKFBOUT (clk_pll_i), .CLKFBOUTB (), .CLKOUT0 (), .CLKOUT0B (), .CLKOUT1 (), .CLKOUT1B (), .CLKOUT2 (), .CLKOUT2B (), .CLKOUT3 (), .CLKOUT3B (), .CLKOUT4 (), .CLKOUT5 (), .CLKOUT6 (), // Input clock control .CLKFBIN (clk_bufg), // From BUFH network .CLKIN1 (pll_clk3), // From PLL .CLKIN2 (1'b0), // Tied to always select the primary input clock .CLKINSEL (1'b1), // Ports for dynamic reconfiguration .DADDR (7'h0), .DCLK (1'b0), .DEN (1'b0), .DI (16'h0), .DO (), .DRDY (), .DWE (1'b0), // Ports for dynamic phase shift .PSCLK (1'b0), .PSEN (1'b0), .PSINCDEC (1'b0), .PSDONE (), // Other control and status signals .LOCKED (MMCM_Locked_i), .CLKINSTOPPED (), .CLKFBSTOPPED (), .PWRDWN (1'b0), .RST (~pll_locked_i)); end endgenerate //*************************************************************************** // RESET SYNCHRONIZATION DESCRIPTION: // Various resets are generated to ensure that: // 1. All resets are synchronously deasserted with respect to the clock // domain they are interfacing to. There are several different clock // domains - each one will receive a synchronized reset. // 2. The reset deassertion order starts with deassertion of SYS_RST, // followed by deassertion of resets for various parts of the design // (see "RESET ORDER" below) based on the lock status of PLLE2s. // RESET ORDER: // 1. User deasserts SYS_RST // 2. Reset PLLE2 and IDELAYCTRL // 3. Wait for PLLE2 and IDELAYCTRL to lock // 4. Release reset for all I/O primitives and internal logic // OTHER NOTES: // 1. Asynchronously assert reset. This way we can assert reset even if // there is no clock (needed for things like 3-stating output buffers // to prevent initial bus contention). Reset deassertion is synchronous. //*************************************************************************** //***************************************************************** // CLKDIV logic reset //***************************************************************** // Wait for PLLE2 and IDELAYCTRL to lock before releasing reset // current O,25.0 unisim phaser_ref never locks. Need to find out why . assign rst_tmp = sys_rst_act_hi | ~iodelay_ctrl_rdy | ~ref_dll_lock | ~MMCM_Locked_i; always @(posedge clk_bufg or posedge rst_tmp) begin if (rst_tmp) begin rstdiv0_sync_r <= #TCQ {RST_DIV_SYNC_NUM-1{1'b1}}; rstdiv0_sync_r1 <= #TCQ 1'b1 ; end else begin rstdiv0_sync_r <= #TCQ rstdiv0_sync_r << 1; rstdiv0_sync_r1 <= #TCQ rstdiv0_sync_r[RST_DIV_SYNC_NUM-2]; end end assign rstdiv0 = rstdiv0_sync_r1 ; assign rst_tmp_phaser_ref = sys_rst_act_hi | ~pll_locked_i | ~iodelay_ctrl_rdy; always @(posedge clk_bufg or posedge rst_tmp_phaser_ref) if (rst_tmp_phaser_ref) rst_phaser_ref_sync_r <= #TCQ {RST_DIV_SYNC_NUM{1'b1}}; else rst_phaser_ref_sync_r <= #TCQ rst_phaser_ref_sync_r << 1; assign rst_phaser_ref = rst_phaser_ref_sync_r[RST_DIV_SYNC_NUM-1]; endmodule
////////////////////////////////////////////////////////////////////////////////// // SharedKESTop.v for Cosmos OpenSSD // Copyright (c) 2015 Hanyang University ENC Lab. // Contributed by Jinwoo Jeong <[email protected]> // Ilyong Jung <[email protected]> // Yong Ho Song <[email protected]> // // This file is part of Cosmos OpenSSD. // // Cosmos OpenSSD 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. // // Cosmos OpenSSD 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 Cosmos OpenSSD; see the file COPYING. // If not, see <http://www.gnu.org/licenses/>. ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// // Company: ENC Lab. <http://enc.hanyang.ac.kr> // Engineer: Jinwoo Jeong <[email protected]> // Ilyong Jung <[email protected]> // // Project Name: Cosmos OpenSSD // Design Name: BCH Page Decoder // Module Name: SharedKESTop // File Name: SharedKESTop.v // // Version: v1.0.0 // // Description: Shared KES top module // ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// // Revision History: // // * v1.0.0 // - first draft ////////////////////////////////////////////////////////////////////////////////// `timescale 1ns / 1ps module SharedKESTop #( parameter Channel = 4, parameter Multi = 2, parameter GaloisFieldDegree = 12, parameter MaxErrorCountBits = 9, parameter Syndromes = 27, parameter ELPCoefficients = 15 ) ( iClock , iReset , oSharedKESReady_0 , iErrorDetectionEnd_0 , iDecodeNeeded_0 , iSyndromes_0 , iCSAvailable_0 , oIntraSharedKESEnd_0 , oErroredChunk_0 , oCorrectionFail_0 , oClusterErrorCount_0 , oELPCoefficients_0 , oSharedKESReady_1 , iErrorDetectionEnd_1 , iDecodeNeeded_1 , iSyndromes_1 , iCSAvailable_1 , oIntraSharedKESEnd_1 , oErroredChunk_1 , oCorrectionFail_1 , oClusterErrorCount_1 , oELPCoefficients_1 , oSharedKESReady_2 , iErrorDetectionEnd_2 , iDecodeNeeded_2 , iSyndromes_2 , iCSAvailable_2 , oIntraSharedKESEnd_2 , oErroredChunk_2 , oCorrectionFail_2 , oClusterErrorCount_2 , oELPCoefficients_2 , oSharedKESReady_3 , iErrorDetectionEnd_3 , iDecodeNeeded_3 , iSyndromes_3 , iCSAvailable_3 , oIntraSharedKESEnd_3 , oErroredChunk_3 , oCorrectionFail_3 , oClusterErrorCount_3 , oELPCoefficients_3 ); input iClock ; input iReset ; output oSharedKESReady_0 ; input [Multi - 1:0] iErrorDetectionEnd_0 ; input [Multi - 1:0] iDecodeNeeded_0 ; input [Multi*GaloisFieldDegree*Syndromes - 1:0] iSyndromes_0 ; input iCSAvailable_0 ; output oIntraSharedKESEnd_0 ; output [Multi - 1:0] oErroredChunk_0 ; output [Multi - 1:0] oCorrectionFail_0 ; output [Multi*MaxErrorCountBits - 1:0] oClusterErrorCount_0 ; output [Multi*GaloisFieldDegree*ELPCoefficients - 1:0] oELPCoefficients_0 ; output oSharedKESReady_1 ; input [Multi - 1:0] iErrorDetectionEnd_1 ; input [Multi - 1:0] iDecodeNeeded_1 ; input [Multi*GaloisFieldDegree*Syndromes - 1:0] iSyndromes_1 ; input iCSAvailable_1 ; output oIntraSharedKESEnd_1 ; output [Multi - 1:0] oErroredChunk_1 ; output [Multi - 1:0] oCorrectionFail_1 ; output [Multi*MaxErrorCountBits - 1:0] oClusterErrorCount_1 ; output [Multi*GaloisFieldDegree*ELPCoefficients - 1:0] oELPCoefficients_1 ; output oSharedKESReady_2 ; input [Multi - 1:0] iErrorDetectionEnd_2 ; input [Multi - 1:0] iDecodeNeeded_2 ; input [Multi*GaloisFieldDegree*Syndromes - 1:0] iSyndromes_2 ; input iCSAvailable_2 ; output oIntraSharedKESEnd_2 ; output [Multi - 1:0] oErroredChunk_2 ; output [Multi - 1:0] oCorrectionFail_2 ; output [Multi*MaxErrorCountBits - 1:0] oClusterErrorCount_2 ; output [Multi*GaloisFieldDegree*ELPCoefficients - 1:0] oELPCoefficients_2 ; output oSharedKESReady_3 ; input [Multi - 1:0] iErrorDetectionEnd_3 ; input [Multi - 1:0] iDecodeNeeded_3 ; input [Multi*GaloisFieldDegree*Syndromes - 1:0] iSyndromes_3 ; input iCSAvailable_3 ; output oIntraSharedKESEnd_3 ; output [Multi - 1:0] oErroredChunk_3 ; output [Multi - 1:0] oCorrectionFail_3 ; output [Multi*MaxErrorCountBits - 1:0] oClusterErrorCount_3 ; output [Multi*GaloisFieldDegree*ELPCoefficients - 1:0] oELPCoefficients_3 ; wire wKESAvailable ; wire wExecuteKES ; wire wErroredChunkNumber ; wire wDataFowarding ; wire wLastChunk ; wire wOutBufferReady ; wire wKESEnd ; wire wKESFail ; wire wCorrectedChunkNumber ; wire wClusterCorrectionEnd ; wire [3:0] wChunkErrorCount ; wire [Channel - 1:0] wChannelSelIn ; wire [Channel - 1:0] wChannelSelOut ; wire [GaloisFieldDegree*Syndromes - 1:0] wSyndromes ; wire [GaloisFieldDegree - 1:0] wELPCoefficient000 ; wire [GaloisFieldDegree - 1:0] wELPCoefficient001 ; wire [GaloisFieldDegree - 1:0] wELPCoefficient002 ; wire [GaloisFieldDegree - 1:0] wELPCoefficient003 ; wire [GaloisFieldDegree - 1:0] wELPCoefficient004 ; wire [GaloisFieldDegree - 1:0] wELPCoefficient005 ; wire [GaloisFieldDegree - 1:0] wELPCoefficient006 ; wire [GaloisFieldDegree - 1:0] wELPCoefficient007 ; wire [GaloisFieldDegree - 1:0] wELPCoefficient008 ; wire [GaloisFieldDegree - 1:0] wELPCoefficient009 ; wire [GaloisFieldDegree - 1:0] wELPCoefficient010 ; wire [GaloisFieldDegree - 1:0] wELPCoefficient011 ; wire [GaloisFieldDegree - 1:0] wELPCoefficient012 ; wire [GaloisFieldDegree - 1:0] wELPCoefficient013 ; wire [GaloisFieldDegree - 1:0] wELPCoefficient014 ; InterChannelSyndromeBuffer #( .Channel(4), .Multi(2), .GaloisFieldDegree(12), .Syndromes(27) ) PageDecoderSyndromeBuffer ( .iClock (iClock ), .iReset (iReset ), .iErrorDetectionEnd ({iErrorDetectionEnd_3, iErrorDetectionEnd_2, iErrorDetectionEnd_1, iErrorDetectionEnd_0} ), .iDecodeNeeded ({iDecodeNeeded_3, iDecodeNeeded_2, iDecodeNeeded_1, iDecodeNeeded_0} ), .iSyndromes ({iSyndromes_3, iSyndromes_2, iSyndromes_1, iSyndromes_0} ), .oSharedKESReady ({oSharedKESReady_3, oSharedKESReady_2, oSharedKESReady_1, oSharedKESReady_0} ), .iKESAvailable (wKESAvailable ), .oExecuteKES (wExecuteKES ), .oErroredChunkNumber (wErroredChunkNumber ), .oDataFowarding (wDataFowarding ), .oLastChunk (wLastChunk ), .oSyndromes (wSyndromes ), .oChannelSel (wChannelSelIn ) ); d_BCH_KES_top PageDecoderKES ( .i_clk (iClock), .i_RESET (iReset), .i_stop_dec (1'b0), .i_channel_sel (wChannelSelIn), .i_execute_kes (wExecuteKES), .i_data_fowarding (wDataFowarding), .i_buf_available (wOutBufferReady), .i_chunk_number (wErroredChunkNumber), .i_buf_sequence_end (wLastChunk), .o_kes_sequence_end (wKESEnd), .o_kes_fail (wKESFail), .o_kes_available (wKESAvailable), .o_chunk_number (wCorrectedChunkNumber), .o_buf_sequence_end (wClusterCorrectionEnd), .o_channel_sel (wChannelSelOut), .o_error_count (wChunkErrorCount), .i_syndromes (wSyndromes), .o_v_2i_000 (wELPCoefficient000), .o_v_2i_001 (wELPCoefficient001), .o_v_2i_002 (wELPCoefficient002), .o_v_2i_003 (wELPCoefficient003), .o_v_2i_004 (wELPCoefficient004), .o_v_2i_005 (wELPCoefficient005), .o_v_2i_006 (wELPCoefficient006), .o_v_2i_007 (wELPCoefficient007), .o_v_2i_008 (wELPCoefficient008), .o_v_2i_009 (wELPCoefficient009), .o_v_2i_010 (wELPCoefficient010), .o_v_2i_011 (wELPCoefficient011), .o_v_2i_012 (wELPCoefficient012), .o_v_2i_013 (wELPCoefficient013), .o_v_2i_014 (wELPCoefficient014) ); InterChannelELPBuffer #( .Channel(4), .Multi(2), .GaloisFieldDegree(12), .ELPCoefficients(15) ) PageDecoderELPBuffer ( .iClock (iClock ), .iReset (iReset ), .iChannelSel (wChannelSelOut ), .iKESEnd (wKESEnd ), .iKESFail (wKESFail ), .iClusterCorrectionEnd (wClusterCorrectionEnd ), .iCorrectedChunkNumber (wCorrectedChunkNumber ), .iChunkErrorCount (wChunkErrorCount ), .oBufferReady (wOutBufferReady ), .iELPCoefficient000 (wELPCoefficient000 ), .iELPCoefficient001 (wELPCoefficient001 ), .iELPCoefficient002 (wELPCoefficient002 ), .iELPCoefficient003 (wELPCoefficient003 ), .iELPCoefficient004 (wELPCoefficient004 ), .iELPCoefficient005 (wELPCoefficient005 ), .iELPCoefficient006 (wELPCoefficient006 ), .iELPCoefficient007 (wELPCoefficient007 ), .iELPCoefficient008 (wELPCoefficient008 ), .iELPCoefficient009 (wELPCoefficient009 ), .iELPCoefficient010 (wELPCoefficient010 ), .iELPCoefficient011 (wELPCoefficient011 ), .iELPCoefficient012 (wELPCoefficient012 ), .iELPCoefficient013 (wELPCoefficient013 ), .iELPCoefficient014 (wELPCoefficient014 ), .iCSAvailable ({iCSAvailable_3, iCSAvailable_2, iCSAvailable_1, iCSAvailable_0} ), .oIntraSharedKESEnd ({oIntraSharedKESEnd_3, oIntraSharedKESEnd_2, oIntraSharedKESEnd_1, oIntraSharedKESEnd_0} ), .oErroredChunk ({oErroredChunk_3, oErroredChunk_2, oErroredChunk_1, oErroredChunk_0} ), .oCorrectionFail ({oCorrectionFail_3, oCorrectionFail_2, oCorrectionFail_1, oCorrectionFail_0} ), .oClusterErrorCount ({oClusterErrorCount_3, oClusterErrorCount_2, oClusterErrorCount_1, oClusterErrorCount_0} ), .oELPCoefficients ({oELPCoefficients_3, oELPCoefficients_2, oELPCoefficients_1, oELPCoefficients_0} ) ); endmodule
(***********************************************************************) (* v * The Coq Proof Assistant / The Coq Development Team *) (* <O___,, * INRIA-Rocquencourt & LRI-CNRS-Orsay *) (* \VV/ *************************************************************) (* // * This file is distributed under the terms of the *) (* * GNU Lesser General Public License Version 2.1 *) (***********************************************************************) (** * An light axiomatization of integers (used in MSetAVL). *) (** We define a signature for an integer datatype based on [Z]. The goal is to allow a switch after extraction to ocaml's [big_int] or even [int] when finiteness isn't a problem (typically : when mesuring the height of an AVL tree). *) Require Import BinInt. Delimit Scope Int_scope with I. Local Open Scope Int_scope. (** * A specification of integers *) Module Type Int. Parameter t : Set. Bind Scope Int_scope with t. Parameter i2z : t -> Z. Parameter _0 : t. Parameter _1 : t. Parameter _2 : t. Parameter _3 : t. Parameter add : t -> t -> t. Parameter opp : t -> t. Parameter sub : t -> t -> t. Parameter mul : t -> t -> t. Parameter max : t -> t -> t. Notation "0" := _0 : Int_scope. Notation "1" := _1 : Int_scope. Notation "2" := _2 : Int_scope. Notation "3" := _3 : Int_scope. Infix "+" := add : Int_scope. Infix "-" := sub : Int_scope. Infix "*" := mul : Int_scope. Notation "- x" := (opp x) : Int_scope. (** For logical relations, we can rely on their counterparts in Z, since they don't appear after extraction. Moreover, using tactics like omega is easier this way. *) Notation "x == y" := (i2z x = i2z y) (at level 70, y at next level, no associativity) : Int_scope. Notation "x <= y" := (i2z x <= i2z y)%Z : Int_scope. Notation "x < y" := (i2z x < i2z y)%Z : Int_scope. Notation "x >= y" := (i2z x >= i2z y)%Z : Int_scope. Notation "x > y" := (i2z x > i2z y)%Z : Int_scope. Notation "x <= y <= z" := (x <= y /\ y <= z) : Int_scope. Notation "x <= y < z" := (x <= y /\ y < z) : Int_scope. Notation "x < y < z" := (x < y /\ y < z) : Int_scope. Notation "x < y <= z" := (x < y /\ y <= z) : Int_scope. (** Informative comparisons. *) Axiom eqb : t -> t -> bool. Axiom ltb : t -> t -> bool. Axiom leb : t -> t -> bool. Infix "=?" := eqb. Infix "<?" := ltb. Infix "<=?" := leb. (** For compatibility, some decidability fonctions (informative). *) Axiom gt_le_dec : forall x y : t, {x > y} + {x <= y}. Axiom ge_lt_dec : forall x y : t, {x >= y} + {x < y}. Axiom eq_dec : forall x y : t, { x == y } + {~ x==y }. (** Specifications *) (** First, we ask [i2z] to be injective. Said otherwise, our ad-hoc equality [==] and the generic [=] are in fact equivalent. We define [==] nonetheless since the translation to [Z] for using automatic tactic is easier. *) Axiom i2z_eq : forall n p : t, n == p -> n = p. (** Then, we express the specifications of the above parameters using their Z counterparts. *) Axiom i2z_0 : i2z _0 = 0%Z. Axiom i2z_1 : i2z _1 = 1%Z. Axiom i2z_2 : i2z _2 = 2%Z. Axiom i2z_3 : i2z _3 = 3%Z. Axiom i2z_add : forall n p, i2z (n + p) = (i2z n + i2z p)%Z. Axiom i2z_opp : forall n, i2z (-n) = (-i2z n)%Z. Axiom i2z_sub : forall n p, i2z (n - p) = (i2z n - i2z p)%Z. Axiom i2z_mul : forall n p, i2z (n * p) = (i2z n * i2z p)%Z. Axiom i2z_max : forall n p, i2z (max n p) = Z.max (i2z n) (i2z p). Axiom i2z_eqb : forall n p, eqb n p = Z.eqb (i2z n) (i2z p). Axiom i2z_ltb : forall n p, ltb n p = Z.ltb (i2z n) (i2z p). Axiom i2z_leb : forall n p, leb n p = Z.leb (i2z n) (i2z p). End Int. (** * Facts and tactics using [Int] *) Module MoreInt (Import I:Int). Local Notation int := I.t. Lemma eqb_eq n p : (n =? p) = true <-> n == p. Proof. now rewrite i2z_eqb, Z.eqb_eq. Qed. Lemma eqb_neq n p : (n =? p) = false <-> ~(n == p). Proof. rewrite <- eqb_eq. destruct (n =? p); intuition. Qed. Lemma ltb_lt n p : (n <? p) = true <-> n < p. Proof. now rewrite i2z_ltb, Z.ltb_lt. Qed. Lemma ltb_nlt n p : (n <? p) = false <-> ~(n < p). Proof. rewrite <- ltb_lt. destruct (n <? p); intuition. Qed. Lemma leb_le n p : (n <=? p) = true <-> n <= p. Proof. now rewrite i2z_leb, Z.leb_le. Qed. Lemma leb_nle n p : (n <=? p) = false <-> ~(n <= p). Proof. rewrite <- leb_le. destruct (n <=? p); intuition. Qed. (** A magic (but costly) tactic that goes from [int] back to the [Z] friendly world ... *) Hint Rewrite -> i2z_0 i2z_1 i2z_2 i2z_3 i2z_add i2z_opp i2z_sub i2z_mul i2z_max i2z_eqb i2z_ltb i2z_leb : i2z. Ltac i2z := match goal with | H : ?a = ?b |- _ => generalize (f_equal i2z H); try autorewrite with i2z; clear H; intro H; i2z | |- ?a = ?b => apply (i2z_eq a b); try autorewrite with i2z; i2z | H : _ |- _ => progress autorewrite with i2z in H; i2z | _ => try autorewrite with i2z end. (** A reflexive version of the [i2z] tactic *) (** this [i2z_refl] is actually weaker than [i2z]. For instance, if a [i2z] is buried deep inside a subterm, [i2z_refl] may miss it. See also the limitation about [Set] or [Type] part below. Anyhow, [i2z_refl] is enough for applying [romega]. *) Ltac i2z_gen := match goal with | |- ?a = ?b => apply (i2z_eq a b); i2z_gen | H : ?a = ?b |- _ => generalize (f_equal i2z H); clear H; i2z_gen | H : eq (A:=Z) ?a ?b |- _ => revert H; i2z_gen | H : Z.lt ?a ?b |- _ => revert H; i2z_gen | H : Z.le ?a ?b |- _ => revert H; i2z_gen | H : Z.gt ?a ?b |- _ => revert H; i2z_gen | H : Z.ge ?a ?b |- _ => revert H; i2z_gen | H : _ -> ?X |- _ => (* A [Set] or [Type] part cannot be dealt with easily using the [ExprP] datatype. So we forget it, leaving a goal that can be weaker than the original. *) match type of X with | Type => clear H; i2z_gen | Prop => revert H; i2z_gen end | H : _ <-> _ |- _ => revert H; i2z_gen | H : _ /\ _ |- _ => revert H; i2z_gen | H : _ \/ _ |- _ => revert H; i2z_gen | H : ~ _ |- _ => revert H; i2z_gen | _ => idtac end. Inductive ExprI : Set := | EI0 : ExprI | EI1 : ExprI | EI2 : ExprI | EI3 : ExprI | EIadd : ExprI -> ExprI -> ExprI | EIopp : ExprI -> ExprI | EIsub : ExprI -> ExprI -> ExprI | EImul : ExprI -> ExprI -> ExprI | EImax : ExprI -> ExprI -> ExprI | EIraw : int -> ExprI. Inductive ExprZ : Set := | EZadd : ExprZ -> ExprZ -> ExprZ | EZopp : ExprZ -> ExprZ | EZsub : ExprZ -> ExprZ -> ExprZ | EZmul : ExprZ -> ExprZ -> ExprZ | EZmax : ExprZ -> ExprZ -> ExprZ | EZofI : ExprI -> ExprZ | EZraw : Z -> ExprZ. Inductive ExprP : Type := | EPeq : ExprZ -> ExprZ -> ExprP | EPlt : ExprZ -> ExprZ -> ExprP | EPle : ExprZ -> ExprZ -> ExprP | EPgt : ExprZ -> ExprZ -> ExprP | EPge : ExprZ -> ExprZ -> ExprP | EPimpl : ExprP -> ExprP -> ExprP | EPequiv : ExprP -> ExprP -> ExprP | EPand : ExprP -> ExprP -> ExprP | EPor : ExprP -> ExprP -> ExprP | EPneg : ExprP -> ExprP | EPraw : Prop -> ExprP. (** [int] to [ExprI] *) Ltac i2ei trm := match constr:trm with | 0 => constr:EI0 | 1 => constr:EI1 | 2 => constr:EI2 | 3 => constr:EI3 | ?x + ?y => let ex := i2ei x with ey := i2ei y in constr:(EIadd ex ey) | ?x - ?y => let ex := i2ei x with ey := i2ei y in constr:(EIsub ex ey) | ?x * ?y => let ex := i2ei x with ey := i2ei y in constr:(EImul ex ey) | max ?x ?y => let ex := i2ei x with ey := i2ei y in constr:(EImax ex ey) | - ?x => let ex := i2ei x in constr:(EIopp ex) | ?x => constr:(EIraw x) end (** [Z] to [ExprZ] *) with z2ez trm := match constr:trm with | (?x + ?y)%Z => let ex := z2ez x with ey := z2ez y in constr:(EZadd ex ey) | (?x - ?y)%Z => let ex := z2ez x with ey := z2ez y in constr:(EZsub ex ey) | (?x * ?y)%Z => let ex := z2ez x with ey := z2ez y in constr:(EZmul ex ey) | (Z.max ?x ?y) => let ex := z2ez x with ey := z2ez y in constr:(EZmax ex ey) | (- ?x)%Z => let ex := z2ez x in constr:(EZopp ex) | i2z ?x => let ex := i2ei x in constr:(EZofI ex) | ?x => constr:(EZraw x) end. (** [Prop] to [ExprP] *) Ltac p2ep trm := match constr:trm with | (?x <-> ?y) => let ex := p2ep x with ey := p2ep y in constr:(EPequiv ex ey) | (?x -> ?y) => let ex := p2ep x with ey := p2ep y in constr:(EPimpl ex ey) | (?x /\ ?y) => let ex := p2ep x with ey := p2ep y in constr:(EPand ex ey) | (?x \/ ?y) => let ex := p2ep x with ey := p2ep y in constr:(EPor ex ey) | (~ ?x) => let ex := p2ep x in constr:(EPneg ex) | (eq (A:=Z) ?x ?y) => let ex := z2ez x with ey := z2ez y in constr:(EPeq ex ey) | (?x < ?y)%Z => let ex := z2ez x with ey := z2ez y in constr:(EPlt ex ey) | (?x <= ?y)%Z => let ex := z2ez x with ey := z2ez y in constr:(EPle ex ey) | (?x > ?y)%Z => let ex := z2ez x with ey := z2ez y in constr:(EPgt ex ey) | (?x >= ?y)%Z => let ex := z2ez x with ey := z2ez y in constr:(EPge ex ey) | ?x => constr:(EPraw x) end. (** [ExprI] to [int] *) Fixpoint ei2i (e:ExprI) : int := match e with | EI0 => 0 | EI1 => 1 | EI2 => 2 | EI3 => 3 | EIadd e1 e2 => (ei2i e1)+(ei2i e2) | EIsub e1 e2 => (ei2i e1)-(ei2i e2) | EImul e1 e2 => (ei2i e1)*(ei2i e2) | EImax e1 e2 => max (ei2i e1) (ei2i e2) | EIopp e => -(ei2i e) | EIraw i => i end. (** [ExprZ] to [Z] *) Fixpoint ez2z (e:ExprZ) : Z := match e with | EZadd e1 e2 => ((ez2z e1)+(ez2z e2))%Z | EZsub e1 e2 => ((ez2z e1)-(ez2z e2))%Z | EZmul e1 e2 => ((ez2z e1)*(ez2z e2))%Z | EZmax e1 e2 => Z.max (ez2z e1) (ez2z e2) | EZopp e => (-(ez2z e))%Z | EZofI e => i2z (ei2i e) | EZraw z => z end. (** [ExprP] to [Prop] *) Fixpoint ep2p (e:ExprP) : Prop := match e with | EPeq e1 e2 => (ez2z e1) = (ez2z e2) | EPlt e1 e2 => ((ez2z e1)<(ez2z e2))%Z | EPle e1 e2 => ((ez2z e1)<=(ez2z e2))%Z | EPgt e1 e2 => ((ez2z e1)>(ez2z e2))%Z | EPge e1 e2 => ((ez2z e1)>=(ez2z e2))%Z | EPimpl e1 e2 => (ep2p e1) -> (ep2p e2) | EPequiv e1 e2 => (ep2p e1) <-> (ep2p e2) | EPand e1 e2 => (ep2p e1) /\ (ep2p e2) | EPor e1 e2 => (ep2p e1) \/ (ep2p e2) | EPneg e => ~ (ep2p e) | EPraw p => p end. (** [ExprI] (supposed under a [i2z]) to a simplified [ExprZ] *) Fixpoint norm_ei (e:ExprI) : ExprZ := match e with | EI0 => EZraw (0%Z) | EI1 => EZraw (1%Z) | EI2 => EZraw (2%Z) | EI3 => EZraw (3%Z) | EIadd e1 e2 => EZadd (norm_ei e1) (norm_ei e2) | EIsub e1 e2 => EZsub (norm_ei e1) (norm_ei e2) | EImul e1 e2 => EZmul (norm_ei e1) (norm_ei e2) | EImax e1 e2 => EZmax (norm_ei e1) (norm_ei e2) | EIopp e => EZopp (norm_ei e) | EIraw i => EZofI (EIraw i) end. (** [ExprZ] to a simplified [ExprZ] *) Fixpoint norm_ez (e:ExprZ) : ExprZ := match e with | EZadd e1 e2 => EZadd (norm_ez e1) (norm_ez e2) | EZsub e1 e2 => EZsub (norm_ez e1) (norm_ez e2) | EZmul e1 e2 => EZmul (norm_ez e1) (norm_ez e2) | EZmax e1 e2 => EZmax (norm_ez e1) (norm_ez e2) | EZopp e => EZopp (norm_ez e) | EZofI e => norm_ei e | EZraw z => EZraw z end. (** [ExprP] to a simplified [ExprP] *) Fixpoint norm_ep (e:ExprP) : ExprP := match e with | EPeq e1 e2 => EPeq (norm_ez e1) (norm_ez e2) | EPlt e1 e2 => EPlt (norm_ez e1) (norm_ez e2) | EPle e1 e2 => EPle (norm_ez e1) (norm_ez e2) | EPgt e1 e2 => EPgt (norm_ez e1) (norm_ez e2) | EPge e1 e2 => EPge (norm_ez e1) (norm_ez e2) | EPimpl e1 e2 => EPimpl (norm_ep e1) (norm_ep e2) | EPequiv e1 e2 => EPequiv (norm_ep e1) (norm_ep e2) | EPand e1 e2 => EPand (norm_ep e1) (norm_ep e2) | EPor e1 e2 => EPor (norm_ep e1) (norm_ep e2) | EPneg e => EPneg (norm_ep e) | EPraw p => EPraw p end. Lemma norm_ei_correct (e:ExprI) : ez2z (norm_ei e) = i2z (ei2i e). Proof. induction e; simpl; i2z; auto; try congruence. Qed. Lemma norm_ez_correct (e:ExprZ) : ez2z (norm_ez e) = ez2z e. Proof. induction e; simpl; i2z; auto; try congruence; apply norm_ei_correct. Qed. Lemma norm_ep_correct (e:ExprP) : ep2p (norm_ep e) <-> ep2p e. Proof. induction e; simpl; rewrite ?norm_ez_correct; intuition. Qed. Lemma norm_ep_correct2 (e:ExprP) : ep2p (norm_ep e) -> ep2p e. Proof. intros; destruct (norm_ep_correct e); auto. Qed. Ltac i2z_refl := i2z_gen; match goal with |- ?t => let e := p2ep t in change (ep2p e); apply norm_ep_correct2; simpl end. (* i2z_refl can be replaced below by (simpl in *; i2z). The reflexive version improves compilation of AVL files by about 15% *) End MoreInt. (** * An implementation of [Int] *) (** It's always nice to know that our [Int] interface is realizable :-) *) Module Z_as_Int <: Int. Local Open Scope Z_scope. Definition t := Z. Definition _0 := 0. Definition _1 := 1. Definition _2 := 2. Definition _3 := 3. Definition add := Z.add. Definition opp := Z.opp. Definition sub := Z.sub. Definition mul := Z.mul. Definition max := Z.max. Definition eqb := Z.eqb. Definition ltb := Z.ltb. Definition leb := Z.leb. Definition eq_dec := Z.eq_dec. Definition gt_le_dec i j : {i > j} + { i <= j }. Proof. generalize (Z.ltb_spec j i). destruct (j <? i); [left|right]; inversion H; trivial. now apply Z.lt_gt. Defined. Definition ge_lt_dec i j : {i >= j} + { i < j }. Proof. generalize (Z.ltb_spec i j). destruct (i <? j); [right|left]; inversion H; trivial. now apply Z.le_ge. Defined. Definition i2z : t -> Z := fun n => n. Lemma i2z_eq n p : i2z n = i2z p -> n = p. Proof. trivial. Qed. Lemma i2z_0 : i2z _0 = 0. Proof. reflexivity. Qed. Lemma i2z_1 : i2z _1 = 1. Proof. reflexivity. Qed. Lemma i2z_2 : i2z _2 = 2. Proof. reflexivity. Qed. Lemma i2z_3 : i2z _3 = 3. Proof. reflexivity. Qed. Lemma i2z_add n p : i2z (n + p) = i2z n + i2z p. Proof. reflexivity. Qed. Lemma i2z_opp n : i2z (- n) = - i2z n. Proof. reflexivity. Qed. Lemma i2z_sub n p : i2z (n - p) = i2z n - i2z p. Proof. reflexivity. Qed. Lemma i2z_mul n p : i2z (n * p) = i2z n * i2z p. Proof. reflexivity. Qed. Lemma i2z_max n p : i2z (max n p) = Z.max (i2z n) (i2z p). Proof. reflexivity. Qed. Lemma i2z_eqb n p : eqb n p = Z.eqb (i2z n) (i2z p). Proof. reflexivity. Qed. Lemma i2z_leb n p : leb n p = Z.leb (i2z n) (i2z p). Proof. reflexivity. Qed. Lemma i2z_ltb n p : ltb n p = Z.ltb (i2z n) (i2z p). Proof. reflexivity. Qed. End Z_as_Int.
(***********************************************************************) (* v * The Coq Proof Assistant / The Coq Development Team *) (* <O___,, * INRIA-Rocquencourt & LRI-CNRS-Orsay *) (* \VV/ *************************************************************) (* // * This file is distributed under the terms of the *) (* * GNU Lesser General Public License Version 2.1 *) (***********************************************************************) (** * An light axiomatization of integers (used in MSetAVL). *) (** We define a signature for an integer datatype based on [Z]. The goal is to allow a switch after extraction to ocaml's [big_int] or even [int] when finiteness isn't a problem (typically : when mesuring the height of an AVL tree). *) Require Import BinInt. Delimit Scope Int_scope with I. Local Open Scope Int_scope. (** * A specification of integers *) Module Type Int. Parameter t : Set. Bind Scope Int_scope with t. Parameter i2z : t -> Z. Parameter _0 : t. Parameter _1 : t. Parameter _2 : t. Parameter _3 : t. Parameter add : t -> t -> t. Parameter opp : t -> t. Parameter sub : t -> t -> t. Parameter mul : t -> t -> t. Parameter max : t -> t -> t. Notation "0" := _0 : Int_scope. Notation "1" := _1 : Int_scope. Notation "2" := _2 : Int_scope. Notation "3" := _3 : Int_scope. Infix "+" := add : Int_scope. Infix "-" := sub : Int_scope. Infix "*" := mul : Int_scope. Notation "- x" := (opp x) : Int_scope. (** For logical relations, we can rely on their counterparts in Z, since they don't appear after extraction. Moreover, using tactics like omega is easier this way. *) Notation "x == y" := (i2z x = i2z y) (at level 70, y at next level, no associativity) : Int_scope. Notation "x <= y" := (i2z x <= i2z y)%Z : Int_scope. Notation "x < y" := (i2z x < i2z y)%Z : Int_scope. Notation "x >= y" := (i2z x >= i2z y)%Z : Int_scope. Notation "x > y" := (i2z x > i2z y)%Z : Int_scope. Notation "x <= y <= z" := (x <= y /\ y <= z) : Int_scope. Notation "x <= y < z" := (x <= y /\ y < z) : Int_scope. Notation "x < y < z" := (x < y /\ y < z) : Int_scope. Notation "x < y <= z" := (x < y /\ y <= z) : Int_scope. (** Informative comparisons. *) Axiom eqb : t -> t -> bool. Axiom ltb : t -> t -> bool. Axiom leb : t -> t -> bool. Infix "=?" := eqb. Infix "<?" := ltb. Infix "<=?" := leb. (** For compatibility, some decidability fonctions (informative). *) Axiom gt_le_dec : forall x y : t, {x > y} + {x <= y}. Axiom ge_lt_dec : forall x y : t, {x >= y} + {x < y}. Axiom eq_dec : forall x y : t, { x == y } + {~ x==y }. (** Specifications *) (** First, we ask [i2z] to be injective. Said otherwise, our ad-hoc equality [==] and the generic [=] are in fact equivalent. We define [==] nonetheless since the translation to [Z] for using automatic tactic is easier. *) Axiom i2z_eq : forall n p : t, n == p -> n = p. (** Then, we express the specifications of the above parameters using their Z counterparts. *) Axiom i2z_0 : i2z _0 = 0%Z. Axiom i2z_1 : i2z _1 = 1%Z. Axiom i2z_2 : i2z _2 = 2%Z. Axiom i2z_3 : i2z _3 = 3%Z. Axiom i2z_add : forall n p, i2z (n + p) = (i2z n + i2z p)%Z. Axiom i2z_opp : forall n, i2z (-n) = (-i2z n)%Z. Axiom i2z_sub : forall n p, i2z (n - p) = (i2z n - i2z p)%Z. Axiom i2z_mul : forall n p, i2z (n * p) = (i2z n * i2z p)%Z. Axiom i2z_max : forall n p, i2z (max n p) = Z.max (i2z n) (i2z p). Axiom i2z_eqb : forall n p, eqb n p = Z.eqb (i2z n) (i2z p). Axiom i2z_ltb : forall n p, ltb n p = Z.ltb (i2z n) (i2z p). Axiom i2z_leb : forall n p, leb n p = Z.leb (i2z n) (i2z p). End Int. (** * Facts and tactics using [Int] *) Module MoreInt (Import I:Int). Local Notation int := I.t. Lemma eqb_eq n p : (n =? p) = true <-> n == p. Proof. now rewrite i2z_eqb, Z.eqb_eq. Qed. Lemma eqb_neq n p : (n =? p) = false <-> ~(n == p). Proof. rewrite <- eqb_eq. destruct (n =? p); intuition. Qed. Lemma ltb_lt n p : (n <? p) = true <-> n < p. Proof. now rewrite i2z_ltb, Z.ltb_lt. Qed. Lemma ltb_nlt n p : (n <? p) = false <-> ~(n < p). Proof. rewrite <- ltb_lt. destruct (n <? p); intuition. Qed. Lemma leb_le n p : (n <=? p) = true <-> n <= p. Proof. now rewrite i2z_leb, Z.leb_le. Qed. Lemma leb_nle n p : (n <=? p) = false <-> ~(n <= p). Proof. rewrite <- leb_le. destruct (n <=? p); intuition. Qed. (** A magic (but costly) tactic that goes from [int] back to the [Z] friendly world ... *) Hint Rewrite -> i2z_0 i2z_1 i2z_2 i2z_3 i2z_add i2z_opp i2z_sub i2z_mul i2z_max i2z_eqb i2z_ltb i2z_leb : i2z. Ltac i2z := match goal with | H : ?a = ?b |- _ => generalize (f_equal i2z H); try autorewrite with i2z; clear H; intro H; i2z | |- ?a = ?b => apply (i2z_eq a b); try autorewrite with i2z; i2z | H : _ |- _ => progress autorewrite with i2z in H; i2z | _ => try autorewrite with i2z end. (** A reflexive version of the [i2z] tactic *) (** this [i2z_refl] is actually weaker than [i2z]. For instance, if a [i2z] is buried deep inside a subterm, [i2z_refl] may miss it. See also the limitation about [Set] or [Type] part below. Anyhow, [i2z_refl] is enough for applying [romega]. *) Ltac i2z_gen := match goal with | |- ?a = ?b => apply (i2z_eq a b); i2z_gen | H : ?a = ?b |- _ => generalize (f_equal i2z H); clear H; i2z_gen | H : eq (A:=Z) ?a ?b |- _ => revert H; i2z_gen | H : Z.lt ?a ?b |- _ => revert H; i2z_gen | H : Z.le ?a ?b |- _ => revert H; i2z_gen | H : Z.gt ?a ?b |- _ => revert H; i2z_gen | H : Z.ge ?a ?b |- _ => revert H; i2z_gen | H : _ -> ?X |- _ => (* A [Set] or [Type] part cannot be dealt with easily using the [ExprP] datatype. So we forget it, leaving a goal that can be weaker than the original. *) match type of X with | Type => clear H; i2z_gen | Prop => revert H; i2z_gen end | H : _ <-> _ |- _ => revert H; i2z_gen | H : _ /\ _ |- _ => revert H; i2z_gen | H : _ \/ _ |- _ => revert H; i2z_gen | H : ~ _ |- _ => revert H; i2z_gen | _ => idtac end. Inductive ExprI : Set := | EI0 : ExprI | EI1 : ExprI | EI2 : ExprI | EI3 : ExprI | EIadd : ExprI -> ExprI -> ExprI | EIopp : ExprI -> ExprI | EIsub : ExprI -> ExprI -> ExprI | EImul : ExprI -> ExprI -> ExprI | EImax : ExprI -> ExprI -> ExprI | EIraw : int -> ExprI. Inductive ExprZ : Set := | EZadd : ExprZ -> ExprZ -> ExprZ | EZopp : ExprZ -> ExprZ | EZsub : ExprZ -> ExprZ -> ExprZ | EZmul : ExprZ -> ExprZ -> ExprZ | EZmax : ExprZ -> ExprZ -> ExprZ | EZofI : ExprI -> ExprZ | EZraw : Z -> ExprZ. Inductive ExprP : Type := | EPeq : ExprZ -> ExprZ -> ExprP | EPlt : ExprZ -> ExprZ -> ExprP | EPle : ExprZ -> ExprZ -> ExprP | EPgt : ExprZ -> ExprZ -> ExprP | EPge : ExprZ -> ExprZ -> ExprP | EPimpl : ExprP -> ExprP -> ExprP | EPequiv : ExprP -> ExprP -> ExprP | EPand : ExprP -> ExprP -> ExprP | EPor : ExprP -> ExprP -> ExprP | EPneg : ExprP -> ExprP | EPraw : Prop -> ExprP. (** [int] to [ExprI] *) Ltac i2ei trm := match constr:trm with | 0 => constr:EI0 | 1 => constr:EI1 | 2 => constr:EI2 | 3 => constr:EI3 | ?x + ?y => let ex := i2ei x with ey := i2ei y in constr:(EIadd ex ey) | ?x - ?y => let ex := i2ei x with ey := i2ei y in constr:(EIsub ex ey) | ?x * ?y => let ex := i2ei x with ey := i2ei y in constr:(EImul ex ey) | max ?x ?y => let ex := i2ei x with ey := i2ei y in constr:(EImax ex ey) | - ?x => let ex := i2ei x in constr:(EIopp ex) | ?x => constr:(EIraw x) end (** [Z] to [ExprZ] *) with z2ez trm := match constr:trm with | (?x + ?y)%Z => let ex := z2ez x with ey := z2ez y in constr:(EZadd ex ey) | (?x - ?y)%Z => let ex := z2ez x with ey := z2ez y in constr:(EZsub ex ey) | (?x * ?y)%Z => let ex := z2ez x with ey := z2ez y in constr:(EZmul ex ey) | (Z.max ?x ?y) => let ex := z2ez x with ey := z2ez y in constr:(EZmax ex ey) | (- ?x)%Z => let ex := z2ez x in constr:(EZopp ex) | i2z ?x => let ex := i2ei x in constr:(EZofI ex) | ?x => constr:(EZraw x) end. (** [Prop] to [ExprP] *) Ltac p2ep trm := match constr:trm with | (?x <-> ?y) => let ex := p2ep x with ey := p2ep y in constr:(EPequiv ex ey) | (?x -> ?y) => let ex := p2ep x with ey := p2ep y in constr:(EPimpl ex ey) | (?x /\ ?y) => let ex := p2ep x with ey := p2ep y in constr:(EPand ex ey) | (?x \/ ?y) => let ex := p2ep x with ey := p2ep y in constr:(EPor ex ey) | (~ ?x) => let ex := p2ep x in constr:(EPneg ex) | (eq (A:=Z) ?x ?y) => let ex := z2ez x with ey := z2ez y in constr:(EPeq ex ey) | (?x < ?y)%Z => let ex := z2ez x with ey := z2ez y in constr:(EPlt ex ey) | (?x <= ?y)%Z => let ex := z2ez x with ey := z2ez y in constr:(EPle ex ey) | (?x > ?y)%Z => let ex := z2ez x with ey := z2ez y in constr:(EPgt ex ey) | (?x >= ?y)%Z => let ex := z2ez x with ey := z2ez y in constr:(EPge ex ey) | ?x => constr:(EPraw x) end. (** [ExprI] to [int] *) Fixpoint ei2i (e:ExprI) : int := match e with | EI0 => 0 | EI1 => 1 | EI2 => 2 | EI3 => 3 | EIadd e1 e2 => (ei2i e1)+(ei2i e2) | EIsub e1 e2 => (ei2i e1)-(ei2i e2) | EImul e1 e2 => (ei2i e1)*(ei2i e2) | EImax e1 e2 => max (ei2i e1) (ei2i e2) | EIopp e => -(ei2i e) | EIraw i => i end. (** [ExprZ] to [Z] *) Fixpoint ez2z (e:ExprZ) : Z := match e with | EZadd e1 e2 => ((ez2z e1)+(ez2z e2))%Z | EZsub e1 e2 => ((ez2z e1)-(ez2z e2))%Z | EZmul e1 e2 => ((ez2z e1)*(ez2z e2))%Z | EZmax e1 e2 => Z.max (ez2z e1) (ez2z e2) | EZopp e => (-(ez2z e))%Z | EZofI e => i2z (ei2i e) | EZraw z => z end. (** [ExprP] to [Prop] *) Fixpoint ep2p (e:ExprP) : Prop := match e with | EPeq e1 e2 => (ez2z e1) = (ez2z e2) | EPlt e1 e2 => ((ez2z e1)<(ez2z e2))%Z | EPle e1 e2 => ((ez2z e1)<=(ez2z e2))%Z | EPgt e1 e2 => ((ez2z e1)>(ez2z e2))%Z | EPge e1 e2 => ((ez2z e1)>=(ez2z e2))%Z | EPimpl e1 e2 => (ep2p e1) -> (ep2p e2) | EPequiv e1 e2 => (ep2p e1) <-> (ep2p e2) | EPand e1 e2 => (ep2p e1) /\ (ep2p e2) | EPor e1 e2 => (ep2p e1) \/ (ep2p e2) | EPneg e => ~ (ep2p e) | EPraw p => p end. (** [ExprI] (supposed under a [i2z]) to a simplified [ExprZ] *) Fixpoint norm_ei (e:ExprI) : ExprZ := match e with | EI0 => EZraw (0%Z) | EI1 => EZraw (1%Z) | EI2 => EZraw (2%Z) | EI3 => EZraw (3%Z) | EIadd e1 e2 => EZadd (norm_ei e1) (norm_ei e2) | EIsub e1 e2 => EZsub (norm_ei e1) (norm_ei e2) | EImul e1 e2 => EZmul (norm_ei e1) (norm_ei e2) | EImax e1 e2 => EZmax (norm_ei e1) (norm_ei e2) | EIopp e => EZopp (norm_ei e) | EIraw i => EZofI (EIraw i) end. (** [ExprZ] to a simplified [ExprZ] *) Fixpoint norm_ez (e:ExprZ) : ExprZ := match e with | EZadd e1 e2 => EZadd (norm_ez e1) (norm_ez e2) | EZsub e1 e2 => EZsub (norm_ez e1) (norm_ez e2) | EZmul e1 e2 => EZmul (norm_ez e1) (norm_ez e2) | EZmax e1 e2 => EZmax (norm_ez e1) (norm_ez e2) | EZopp e => EZopp (norm_ez e) | EZofI e => norm_ei e | EZraw z => EZraw z end. (** [ExprP] to a simplified [ExprP] *) Fixpoint norm_ep (e:ExprP) : ExprP := match e with | EPeq e1 e2 => EPeq (norm_ez e1) (norm_ez e2) | EPlt e1 e2 => EPlt (norm_ez e1) (norm_ez e2) | EPle e1 e2 => EPle (norm_ez e1) (norm_ez e2) | EPgt e1 e2 => EPgt (norm_ez e1) (norm_ez e2) | EPge e1 e2 => EPge (norm_ez e1) (norm_ez e2) | EPimpl e1 e2 => EPimpl (norm_ep e1) (norm_ep e2) | EPequiv e1 e2 => EPequiv (norm_ep e1) (norm_ep e2) | EPand e1 e2 => EPand (norm_ep e1) (norm_ep e2) | EPor e1 e2 => EPor (norm_ep e1) (norm_ep e2) | EPneg e => EPneg (norm_ep e) | EPraw p => EPraw p end. Lemma norm_ei_correct (e:ExprI) : ez2z (norm_ei e) = i2z (ei2i e). Proof. induction e; simpl; i2z; auto; try congruence. Qed. Lemma norm_ez_correct (e:ExprZ) : ez2z (norm_ez e) = ez2z e. Proof. induction e; simpl; i2z; auto; try congruence; apply norm_ei_correct. Qed. Lemma norm_ep_correct (e:ExprP) : ep2p (norm_ep e) <-> ep2p e. Proof. induction e; simpl; rewrite ?norm_ez_correct; intuition. Qed. Lemma norm_ep_correct2 (e:ExprP) : ep2p (norm_ep e) -> ep2p e. Proof. intros; destruct (norm_ep_correct e); auto. Qed. Ltac i2z_refl := i2z_gen; match goal with |- ?t => let e := p2ep t in change (ep2p e); apply norm_ep_correct2; simpl end. (* i2z_refl can be replaced below by (simpl in *; i2z). The reflexive version improves compilation of AVL files by about 15% *) End MoreInt. (** * An implementation of [Int] *) (** It's always nice to know that our [Int] interface is realizable :-) *) Module Z_as_Int <: Int. Local Open Scope Z_scope. Definition t := Z. Definition _0 := 0. Definition _1 := 1. Definition _2 := 2. Definition _3 := 3. Definition add := Z.add. Definition opp := Z.opp. Definition sub := Z.sub. Definition mul := Z.mul. Definition max := Z.max. Definition eqb := Z.eqb. Definition ltb := Z.ltb. Definition leb := Z.leb. Definition eq_dec := Z.eq_dec. Definition gt_le_dec i j : {i > j} + { i <= j }. Proof. generalize (Z.ltb_spec j i). destruct (j <? i); [left|right]; inversion H; trivial. now apply Z.lt_gt. Defined. Definition ge_lt_dec i j : {i >= j} + { i < j }. Proof. generalize (Z.ltb_spec i j). destruct (i <? j); [right|left]; inversion H; trivial. now apply Z.le_ge. Defined. Definition i2z : t -> Z := fun n => n. Lemma i2z_eq n p : i2z n = i2z p -> n = p. Proof. trivial. Qed. Lemma i2z_0 : i2z _0 = 0. Proof. reflexivity. Qed. Lemma i2z_1 : i2z _1 = 1. Proof. reflexivity. Qed. Lemma i2z_2 : i2z _2 = 2. Proof. reflexivity. Qed. Lemma i2z_3 : i2z _3 = 3. Proof. reflexivity. Qed. Lemma i2z_add n p : i2z (n + p) = i2z n + i2z p. Proof. reflexivity. Qed. Lemma i2z_opp n : i2z (- n) = - i2z n. Proof. reflexivity. Qed. Lemma i2z_sub n p : i2z (n - p) = i2z n - i2z p. Proof. reflexivity. Qed. Lemma i2z_mul n p : i2z (n * p) = i2z n * i2z p. Proof. reflexivity. Qed. Lemma i2z_max n p : i2z (max n p) = Z.max (i2z n) (i2z p). Proof. reflexivity. Qed. Lemma i2z_eqb n p : eqb n p = Z.eqb (i2z n) (i2z p). Proof. reflexivity. Qed. Lemma i2z_leb n p : leb n p = Z.leb (i2z n) (i2z p). Proof. reflexivity. Qed. Lemma i2z_ltb n p : ltb n p = Z.ltb (i2z n) (i2z p). Proof. reflexivity. Qed. End Z_as_Int.
////////////////////////////////////////////////////////////////////////////////// // d_KES_PE_DC_NMLodr.v for Cosmos OpenSSD // Copyright (c) 2015 Hanyang University ENC Lab. // Contributed by Jinwoo Jeong <[email protected]> // Ilyong Jung <[email protected]> // Yong Ho Song <[email protected]> // // This file is part of Cosmos OpenSSD. // // Cosmos OpenSSD 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. // // Cosmos OpenSSD 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 Cosmos OpenSSD; see the file COPYING. // If not, see <http://www.gnu.org/licenses/>. ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// // Company: ENC Lab. <http://enc.hanyang.ac.kr> // Engineer: Jinwoo Jeong <[email protected]> // Ilyong Jung <[email protected]> // // Project Name: Cosmos OpenSSD // Design Name: BCH Page Decoder // Module Name: d_KES_PE_DC_NMLodr // File Name: d_KES_PE_DC_NMLodr.v // // Version: v1.1.1-256B_T14 // // Description: // - Processing Element: Discrepancy Computation module, normal order // - for binary version of inversion-less Berlekamp-Massey algorithm (iBM.b) // - for data area ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////// // Revision History: // // * v1.1.1 // - minor modification for releasing // // * v1.1.0 // - change state machine: divide states // - insert additional registers // - improve frequency characteristic // // * v1.0.0 // - first draft ////////////////////////////////////////////////////////////////////////////////// `include "d_KES_parameters.vh" `timescale 1ns / 1ps module d_KES_PE_DC_NMLodr // discrepancy computation module: normal order ( input wire i_clk, input wire i_RESET_KES, input wire i_stop_dec, input wire i_EXECUTE_PE_DC, input wire [`D_KES_GF_ORDER-1:0] i_S_in, input wire [`D_KES_GF_ORDER-1:0] i_v_2i_X, output wire [`D_KES_GF_ORDER-1:0] o_S_out, output wire [`D_KES_GF_ORDER-1:0] o_coef_2ip1 ); parameter [11:0] D_KES_VALUE_ZERO = 12'b0000_0000_0000; parameter [11:0] D_KES_VALUE_ONE = 12'b0000_0000_0001; // FSM parameters parameter PE_DC_RST = 2'b01; // reset parameter PE_DC_INP = 2'b10; // input capture // variable declaration reg [1:0] r_cur_state; reg [1:0] r_nxt_state; reg [`D_KES_GF_ORDER-1:0] r_S_in_b; reg [`D_KES_GF_ORDER-1:0] r_v_2i_X_b; wire [`D_KES_GF_ORDER-1:0] w_coef_term; // update current state to next state always @ (posedge i_clk) begin if ((i_RESET_KES) || (i_stop_dec)) begin r_cur_state <= PE_DC_RST; end else begin r_cur_state <= r_nxt_state; end end // decide next state always @ ( * ) begin case (r_cur_state) PE_DC_RST: begin r_nxt_state <= (i_EXECUTE_PE_DC)? (PE_DC_INP):(PE_DC_RST); end PE_DC_INP: begin r_nxt_state <= PE_DC_RST; end default: begin r_nxt_state <= PE_DC_RST; end endcase end // state behaviour always @ (posedge i_clk) begin if ((i_RESET_KES) || (i_stop_dec)) begin // initializing r_S_in_b <= 0; r_v_2i_X_b <= 0; end else begin case (r_nxt_state) PE_DC_RST: begin // hold original data r_S_in_b <= r_S_in_b; r_v_2i_X_b <= r_v_2i_X_b; end PE_DC_INP: begin // input capture only r_S_in_b <= i_S_in; r_v_2i_X_b <= i_v_2i_X; end default: begin r_S_in_b <= r_S_in_b; r_v_2i_X_b <= r_v_2i_X_b; end endcase end end d_parallel_FFM_gate_GF12 d_S_in_FFM_v_2i_X ( .i_poly_form_A (r_S_in_b[`D_KES_GF_ORDER-1:0]), .i_poly_form_B (r_v_2i_X_b[`D_KES_GF_ORDER-1:0]), .o_poly_form_result(w_coef_term[`D_KES_GF_ORDER-1:0])); assign o_S_out[`D_KES_GF_ORDER-1:0] = r_S_in_b[`D_KES_GF_ORDER-1:0]; assign o_coef_2ip1 = w_coef_term; endmodule
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * 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. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // 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 REGENTS OF THE // UNIVERSITY OF CALIFORNIA 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. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: rotate.v // Version: 1.00 // Verilog Standard: Verilog-2001 // Description: A simple module to perform to rotate the input data // Author: Dustin Richmond (@darichmond) //----------------------------------------------------------------------------- `timescale 1ns/1ns `include "functions.vh" module rotate #( parameter C_DIRECTION = "LEFT", parameter C_WIDTH = 4 ) ( input [C_WIDTH-1:0] WR_DATA, input [clog2s(C_WIDTH)-1:0] WR_SHIFTAMT, output [C_WIDTH-1:0] RD_DATA ); wire [2*C_WIDTH-1:0] wPreShiftR; wire [2*C_WIDTH-1:0] wPreShiftL; wire [2*C_WIDTH-1:0] wShiftR; wire [2*C_WIDTH-1:0] wShiftL; assign wPreShiftL = {WR_DATA,WR_DATA}; assign wPreShiftR = {WR_DATA,WR_DATA}; assign wShiftL = wPreShiftL << WR_SHIFTAMT; assign wShiftR = wPreShiftR >> WR_SHIFTAMT; generate if(C_DIRECTION == "LEFT") begin assign RD_DATA = wShiftL[2*C_WIDTH-1:C_WIDTH]; end else if (C_DIRECTION == "RIGHT") begin assign RD_DATA = wShiftR[C_WIDTH-1:0]; end endgenerate endmodule
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * 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. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // 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 REGENTS OF THE // UNIVERSITY OF CALIFORNIA 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. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: rotate.v // Version: 1.00 // Verilog Standard: Verilog-2001 // Description: A simple module to perform to rotate the input data // Author: Dustin Richmond (@darichmond) //----------------------------------------------------------------------------- `timescale 1ns/1ns `include "functions.vh" module rotate #( parameter C_DIRECTION = "LEFT", parameter C_WIDTH = 4 ) ( input [C_WIDTH-1:0] WR_DATA, input [clog2s(C_WIDTH)-1:0] WR_SHIFTAMT, output [C_WIDTH-1:0] RD_DATA ); wire [2*C_WIDTH-1:0] wPreShiftR; wire [2*C_WIDTH-1:0] wPreShiftL; wire [2*C_WIDTH-1:0] wShiftR; wire [2*C_WIDTH-1:0] wShiftL; assign wPreShiftL = {WR_DATA,WR_DATA}; assign wPreShiftR = {WR_DATA,WR_DATA}; assign wShiftL = wPreShiftL << WR_SHIFTAMT; assign wShiftR = wPreShiftR >> WR_SHIFTAMT; generate if(C_DIRECTION == "LEFT") begin assign RD_DATA = wShiftL[2*C_WIDTH-1:C_WIDTH]; end else if (C_DIRECTION == "RIGHT") begin assign RD_DATA = wShiftR[C_WIDTH-1:0]; end endgenerate endmodule
/* * This is a post-synthesis test for the blif01a.v test. Run this * simulation in these steps: * * $ iverilog -tblif -o foo.blif blif01a.v * $ abc * abc 01> read_blif foo.blif * abc 02> write_verilog foo.v * abc 03> quit * $ iverilog -g2009 -o foo.vvp blif02a_tb.v foo.v * $ vvp foo.vvp */ module main; parameter WID = 4; reg [WID-1:0] A, B; wire QE, QN, QGT, QGE; cmpN ucmp(.\A[3] (A[3]), .\A[2] (A[2]), .\A[1] (A[1]), .\A[0] (A[0]), .\B[3] (B[3]), .\B[2] (B[2]), .\B[1] (B[1]), .\B[0] (B[0]), .QE(QE), .QN(QN), .QGT(QGT), .QGE(QGE)); int adx; int bdx; initial begin for (bdx = 0 ; bdx[WID]==0 ; bdx = bdx+1) begin for (adx = 0 ; adx[WID]==0 ; adx = adx+1) begin A <= adx[WID-1:0]; B <= bdx[WID-1:0]; #1 ; if (QE !== (adx[WID-1:0]==bdx[WID-1:0])) begin $display("FAILED -- A=%b, B=%b, QE=%b", A, B, QE); $finish; end if (QN !== (adx[WID-1:0]!=bdx[WID-1:0])) begin $display("FAILED -- A=%b, B=%b, QN=%b", A, B, QN); $finish; end if (QGT !== (adx[WID-1:0] > bdx[WID-1:0])) begin $display("FAILED -- A=%b, B=%b, QGT=%b", A, B, QGT); $finish; end if (QGE !== (adx[WID-1:0] >= bdx[WID-1:0])) begin $display("FAILED -- A=%b, B=%b, QGE=%b", A, B, QGE); $finish; end end end $display("PASSED"); end endmodule // main
/* * This is a post-synthesis test for the blif01a.v test. Run this * simulation in these steps: * * $ iverilog -tblif -o foo.blif blif01a.v * $ abc * abc 01> read_blif foo.blif * abc 02> write_verilog foo.v * abc 03> quit * $ iverilog -g2009 -o foo.vvp blif02a_tb.v foo.v * $ vvp foo.vvp */ module main; parameter WID = 4; reg [WID-1:0] A, B; wire QE, QN, QGT, QGE; cmpN ucmp(.\A[3] (A[3]), .\A[2] (A[2]), .\A[1] (A[1]), .\A[0] (A[0]), .\B[3] (B[3]), .\B[2] (B[2]), .\B[1] (B[1]), .\B[0] (B[0]), .QE(QE), .QN(QN), .QGT(QGT), .QGE(QGE)); int adx; int bdx; initial begin for (bdx = 0 ; bdx[WID]==0 ; bdx = bdx+1) begin for (adx = 0 ; adx[WID]==0 ; adx = adx+1) begin A <= adx[WID-1:0]; B <= bdx[WID-1:0]; #1 ; if (QE !== (adx[WID-1:0]==bdx[WID-1:0])) begin $display("FAILED -- A=%b, B=%b, QE=%b", A, B, QE); $finish; end if (QN !== (adx[WID-1:0]!=bdx[WID-1:0])) begin $display("FAILED -- A=%b, B=%b, QN=%b", A, B, QN); $finish; end if (QGT !== (adx[WID-1:0] > bdx[WID-1:0])) begin $display("FAILED -- A=%b, B=%b, QGT=%b", A, B, QGT); $finish; end if (QGE !== (adx[WID-1:0] >= bdx[WID-1:0])) begin $display("FAILED -- A=%b, B=%b, QGE=%b", A, B, QGE); $finish; end end end $display("PASSED"); end endmodule // main
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * 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. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // 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 REGENTS OF THE // UNIVERSITY OF CALIFORNIA 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. // ---------------------------------------------------------------------- `timescale 1ns / 1ps ////////////////////////////////////////////////////////////////////////////////// // Company: // Engineer: // // Create Date: 19:27:32 06/14/2012 // Design Name: // Module Name: reorder_queue_output // Project Name: // Target Devices: // Tool versions: // Description: // Outputs stored TLPs in increasing tag order. // // Dependencies: // reorder_queue.v // // Revision: // Revision 0.01 - File Created // Additional Comments: // ////////////////////////////////////////////////////////////////////////////////// `include "trellis.vh" module reorder_queue_output #( parameter C_PCI_DATA_WIDTH = 9'd128, parameter C_NUM_CHNL = 4'd12, parameter C_TAG_WIDTH = 5, // Number of outstanding requests parameter C_TAG_DW_COUNT_WIDTH = 8, // Width of max count DWs per packet parameter C_DATA_ADDR_STRIDE_WIDTH = 5, // Width of max num stored data addr positions per tag parameter C_DATA_ADDR_WIDTH = 10, // Width of stored data address // Local parameters parameter C_PCI_DATA_WORD = C_PCI_DATA_WIDTH/32, parameter C_PCI_DATA_WORD_WIDTH = clog2s(C_PCI_DATA_WORD), parameter C_PCI_DATA_COUNT_WIDTH = clog2s(C_PCI_DATA_WORD+1), parameter C_NUM_TAGS = 2**C_TAG_WIDTH ) ( input CLK, // Clock input RST, // Synchronous reset output [C_DATA_ADDR_WIDTH-1:0] DATA_ADDR, // Address of stored packet data input [C_PCI_DATA_WIDTH-1:0] DATA, // Stored packet data input [C_NUM_TAGS-1:0] TAG_FINISHED, // Bitmap of finished tags output [C_NUM_TAGS-1:0] TAG_CLEAR, // Bitmap of tags to clear output [C_TAG_WIDTH-1:0] TAG, // Tag for which to retrieve packet data input [5:0] TAG_MAPPED, // Mapped tag (i.e. internal tag) input [C_TAG_DW_COUNT_WIDTH-1:0] PKT_WORDS, // Total count of packet payload in DWs input PKT_WORDS_LTE1, // True if total count of packet payload is <= 4 DWs input PKT_WORDS_LTE2, // True if total count of packet payload is <= 8 DWs input PKT_DONE, // Packet done flag input PKT_ERR, // Packet error flag output [C_PCI_DATA_WIDTH-1:0] ENG_DATA, // Engine data output [(C_NUM_CHNL*C_PCI_DATA_COUNT_WIDTH)-1:0] MAIN_DATA_EN, // Main data enable output [C_NUM_CHNL-1:0] MAIN_DONE, // Main data complete output [C_NUM_CHNL-1:0] MAIN_ERR, // Main data completed with error output [(C_NUM_CHNL*C_PCI_DATA_COUNT_WIDTH)-1:0] SG_RX_DATA_EN, // Scatter gather for RX data enable output [C_NUM_CHNL-1:0] SG_RX_DONE, // Scatter gather for RX data complete output [C_NUM_CHNL-1:0] SG_RX_ERR, // Scatter gather for RX data completed with error output [(C_NUM_CHNL*C_PCI_DATA_COUNT_WIDTH)-1:0] SG_TX_DATA_EN, // Scatter gather for TX data enable output [C_NUM_CHNL-1:0] SG_TX_DONE, // Scatter gather for TX data complete output [C_NUM_CHNL-1:0] SG_TX_ERR // Scatter gather for TX data completed with error ); reg [1:0] rState=0; reg [C_DATA_ADDR_WIDTH-1:0] rDataAddr=0; reg [C_PCI_DATA_WIDTH-1:0] rData=0; reg rTagFinished=0; reg [C_NUM_TAGS-1:0] rClear=0; reg [C_TAG_WIDTH-1:0] rTag=0; reg [C_TAG_WIDTH-1:0] rTagCurr=0; wire [C_TAG_WIDTH-1:0] wTagNext = rTag + 1'd1; reg [5:0] rShift; reg rDone=0; reg rDoneLast=0; reg rErr=0; reg rErrLast=0; reg [C_PCI_DATA_COUNT_WIDTH-1:0] rDE=0; reg [C_TAG_DW_COUNT_WIDTH-1:0] rWords=0; reg rLTE2Pkts=0; reg [C_PCI_DATA_WIDTH-1:0] rDataOut={C_PCI_DATA_WIDTH{1'b0}}; reg [(3*16*C_PCI_DATA_COUNT_WIDTH)-1:0] rDEOut={3*16*C_PCI_DATA_COUNT_WIDTH{1'd0}}; reg [(3*16)-1:0] rDoneOut={3*16{1'd0}}; reg [(3*16)-1:0] rErrOut={3*16{1'd0}}; assign DATA_ADDR = rDataAddr; assign TAG = rTag; assign TAG_CLEAR = rClear; assign ENG_DATA = rDataOut; assign MAIN_DATA_EN = rDEOut[(0*16*C_PCI_DATA_COUNT_WIDTH) +:(C_NUM_CHNL*C_PCI_DATA_COUNT_WIDTH)]; assign MAIN_DONE = rDoneOut[(0*16) +:C_NUM_CHNL]; assign MAIN_ERR = rErrOut[(0*16) +:C_NUM_CHNL]; assign SG_RX_DATA_EN = rDEOut[(1*16*C_PCI_DATA_COUNT_WIDTH) +:(C_NUM_CHNL*C_PCI_DATA_COUNT_WIDTH)]; assign SG_RX_DONE = rDoneOut[(1*16) +:C_NUM_CHNL]; assign SG_RX_ERR = rErrOut[(1*16) +:C_NUM_CHNL]; assign SG_TX_DATA_EN = rDEOut[(2*16*C_PCI_DATA_COUNT_WIDTH) +:(C_NUM_CHNL*C_PCI_DATA_COUNT_WIDTH)]; assign SG_TX_DONE = rDoneOut[(2*16) +:C_NUM_CHNL]; assign SG_TX_ERR = rErrOut[(2*16) +:C_NUM_CHNL]; // Output completed data in increasing tag order, avoid stalls if possible always @ (posedge CLK) begin if (RST) begin rState <= #1 0; rTag <= #1 0; rDataAddr <= #1 0; rDone <= #1 0; rErr <= #1 0; rDE <= #1 0; rClear <= #1 0; rTagFinished <= #1 0; rShift <= 0; // Added end else begin rTagFinished <= #1 TAG_FINISHED[rTag]; case (rState) 2'd0: begin // Request initial data and final info, output nothing rDone <= #1 0; rErr <= #1 0; rDE <= #1 0; rClear <= #1 0; if (rTagFinished) begin rTag <= #1 wTagNext; rTagCurr <= #1 rTag; rDataAddr <= #1 rDataAddr + 1'd1; rState <= #1 2'd2; end else begin rState <= #1 2'd0; end end 2'd1: begin // Request initial data and final info, output last data rDone <= #1 rDoneLast; rErr <= #1 rErrLast; rDE <= #1 rWords[C_PCI_DATA_COUNT_WIDTH-1:0]; rClear <= #1 1<<rTagCurr; // Clear the tag if (rTagFinished) begin rTag <= #1 wTagNext; rTagCurr <= #1 rTag; rDataAddr <= #1 rDataAddr + 1'd1; rState <= #1 2'd2; end else begin rState <= #1 2'd0; end end 2'd2: begin // Initial data now available, output data rShift <= #1 TAG_MAPPED; rDoneLast <= #1 PKT_DONE; rErrLast <= #1 PKT_ERR; rWords <= #1 PKT_WORDS - C_PCI_DATA_WORD[C_PCI_DATA_WORD_WIDTH:0]; rLTE2Pkts <= #1 (PKT_WORDS <= (C_PCI_DATA_WORD*3)); if (PKT_WORDS_LTE1) begin // Guessed wrong, no addl data, need to reset rDone <= #1 PKT_DONE; rErr <= #1 PKT_ERR; rDE <= #1 PKT_WORDS[C_PCI_DATA_COUNT_WIDTH-1:0]; rClear <= #1 1<<rTagCurr; // Clear the tag rDataAddr <= #1 rTag<<C_DATA_ADDR_STRIDE_WIDTH; // rTag is already on the next rState <= #1 2'd0; end else if (PKT_WORDS_LTE2) begin // Guessed right, end of data, output last and continue rDone <= #1 0; rErr <= #1 0; rDE <= #1 C_PCI_DATA_WORD[C_PCI_DATA_WORD_WIDTH:0]; rClear <= #1 0; rDataAddr <= #1 rTag<<C_DATA_ADDR_STRIDE_WIDTH; // rTag is already on the next rState <= #1 2'd1; end else begin // Guessed right, more data, output it and continue rDone <= #1 0; rErr <= #1 0; rDE <= #1 C_PCI_DATA_WORD[C_PCI_DATA_WORD_WIDTH:0]; rClear <= #1 0; rDataAddr <= #1 rDataAddr + 1'd1; rState <= #1 2'd3; end end 2'd3: begin // Next data now available, output data rDone <= #1 0; rErr <= #1 0; rDE <= #1 C_PCI_DATA_WORD[C_PCI_DATA_WORD_WIDTH:0]; rWords <= #1 rWords - C_PCI_DATA_WORD[C_PCI_DATA_WORD_WIDTH:0]; rLTE2Pkts <= #1 (rWords <= (C_PCI_DATA_WORD*3)); if (rLTE2Pkts) begin // End of data, output last and continue rDataAddr <= #1 rTag<<C_DATA_ADDR_STRIDE_WIDTH; // rTag is already on the next rState <= #1 2'd1; end else begin // More data, output it and continue rDataAddr <= #1 rDataAddr + 1'd1; rState <= #1 2'd3; end end endcase end end // Output the data always @ (posedge CLK) begin rData <= #1 DATA; rDataOut <= #1 rData; if (RST) begin rDEOut <= #1 0; rDoneOut <= #1 0; rErrOut <= #1 0; end else begin rDEOut <= #1 rDE<<(C_PCI_DATA_COUNT_WIDTH*rShift); rDoneOut <= #1 (rDone | rErr)<<rShift; rErrOut <= #1 rErr<<rShift; end end /* wire [35:0] wControl0; chipscope_icon_1 cs_icon( .CONTROL0(wControl0) ); chipscope_ila_t8_512 a0( .CLK(DVI_CLK), .CONTROL(wControl0), .TRIG0({wFifoFull, wFifoEmpty, rState, rPrevDVI_VS, DVI_DE, DVI_HS, DVI_VS}), .DATA({457'd0, rCount, // 21 rFrameCount, // 21 wCapture, // 1 RD_EN, // 1 RD_EMPTY, // 1 EOF, // 1 wPackerFull, // 1 wFifoFull, // 1 wFifoEmpty, // 1 rState, // 2 rPrevDVI_VS, // 1 DVI_DE, // 1 DVI_HS, // 1 DVI_VS}) // 1 ); */ endmodule
`timescale 1ns / 1ps ////////////////////////////////////////////////////////////////////////////////// // Company: // Engineer: // // Create Date: 16:58:11 07/01/2012 // Design Name: // Module Name: Device_led // Project Name: // Target Devices: // Tool versions: // Description: // // Dependencies: // // Revision: // Revision 0.01 - File Created // Additional Comments: // ////////////////////////////////////////////////////////////////////////////////// module GPIO(input clk, //ʱÖÓ input rst, //¸´Î» input Start, //´®ÐÐɨÃèÆô¶¯ input EN, //PIO/LEDÏÔʾˢÐÂʹÄÜ input [31:0] P_Data, //²¢ÐÐÊäÈ룬ÓÃÓÚ´®ÐÐÊä³öÊý¾Ý output reg[1:0] counter_set, //ÓÃÓÚ¼ÆÊý/¶¨Ê±Ä£¿é¿ØÖÆ£¬±¾ÊµÑé²»Óà output [15:0] LED_out, //²¢ÐÐÊä³öÊý¾Ý output wire ledclk, //´®ÐÐÒÆÎ»Ê±ÖÓ output wire ledsout, //´®ÐÐÊä³ö output wire ledclrn, //LEDÏÔʾÇåÁã output wire LEDEN, //LEDÏÔʾˢÐÂʹÄÜ output reg[13:0] GPIOf0 //´ýÓãºGPIO ); endmodule
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * 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. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // 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 REGENTS OF THE // UNIVERSITY OF CALIFORNIA 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. // ---------------------------------------------------------------------- // ---------------------------------------------------------------------- // Filename: Filename: tx_multiplexer_64.v // Version: Version: 1.0 // Verilog Standard: Verilog-2005 // Description: the TX Multiplexer services read and write requests from // RIFFA channels in round robin order. // Author: Dustin Richmond (@darichmond) // ---------------------------------------------------------------------- `define FMT_TXENGUPR64_WR32 7'b10_00000 `define FMT_TXENGUPR64_RD32 7'b00_00000 `define FMT_TXENGUPR64_WR64 7'b11_00000 `define FMT_TXENGUPR64_RD64 7'b01_00000 `define S_TXENGUPR64_MAIN_IDLE 4'b0001 `define S_TXENGUPR64_MAIN_RD 4'b0010 `define S_TXENGUPR64_MAIN_WR 4'b0100 `define S_TXENGUPR64_MAIN_WAIT 4'b1000 `define S_TXENGUPR64_CAP_RD_WR 4'b0001 `define S_TXENGUPR64_CAP_WR_RD 4'b0010 `define S_TXENGUPR64_CAP_CAP 4'b0100 `define S_TXENGUPR64_CAP_REL 4'b1000 `include "trellis.vh" `timescale 1ns/1ns module tx_multiplexer_64 #( parameter C_PCI_DATA_WIDTH = 128, parameter C_NUM_CHNL = 12, parameter C_TAG_WIDTH = 5, // Number of outstanding requests parameter C_VENDOR = "ALTERA" ) ( input CLK, input RST_IN, input [C_NUM_CHNL-1:0] WR_REQ, // Write request input [(C_NUM_CHNL*`SIG_ADDR_W)-1:0] WR_ADDR, // Write address input [(C_NUM_CHNL*`SIG_LEN_W)-1:0] WR_LEN, // Write data length input [(C_NUM_CHNL*C_PCI_DATA_WIDTH)-1:0] WR_DATA, // Write data output [C_NUM_CHNL-1:0] WR_DATA_REN, // Write data read enable output [C_NUM_CHNL-1:0] WR_ACK, // Write request has been accepted input [C_NUM_CHNL-1:0] RD_REQ, // Read request input [(C_NUM_CHNL*2)-1:0] RD_SG_CHNL, // Read request channel for scatter gather lists input [(C_NUM_CHNL*`SIG_ADDR_W)-1:0] RD_ADDR, // Read request address input [(C_NUM_CHNL*`SIG_LEN_W)-1:0] RD_LEN, // Read request length output [C_NUM_CHNL-1:0] RD_ACK, // Read request has been accepted output [5:0] INT_TAG, // Internal tag to exchange with external output INT_TAG_VALID, // High to signal tag exchange input [C_TAG_WIDTH-1:0] EXT_TAG, // External tag to provide in exchange for internal tag input EXT_TAG_VALID, // High to signal external tag is valid output TX_ENG_RD_REQ_SENT, // Read completion request issued input RXBUF_SPACE_AVAIL, // Interface: TXR Engine output TXR_DATA_VALID, output [C_PCI_DATA_WIDTH-1:0] TXR_DATA, output TXR_DATA_START_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] TXR_DATA_START_OFFSET, output TXR_DATA_END_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] TXR_DATA_END_OFFSET, input TXR_DATA_READY, output TXR_META_VALID, output [`SIG_FBE_W-1:0] TXR_META_FDWBE, output [`SIG_LBE_W-1:0] TXR_META_LDWBE, output [`SIG_ADDR_W-1:0] TXR_META_ADDR, output [`SIG_LEN_W-1:0] TXR_META_LENGTH, output [`SIG_TAG_W-1:0] TXR_META_TAG, output [`SIG_TC_W-1:0] TXR_META_TC, output [`SIG_ATTR_W-1:0] TXR_META_ATTR, output [`SIG_TYPE_W-1:0] TXR_META_TYPE, output TXR_META_EP, input TXR_META_READY); localparam C_DATA_DELAY = 6'd6; // Delays read/write params to accommodate tx_port_buffer delay and tx_engine_formatter delay. (* syn_encoding = "user" *) (* fsm_encoding = "user" *) reg [3:0] rMainState=`S_TXENGUPR64_MAIN_IDLE, _rMainState=`S_TXENGUPR64_MAIN_IDLE; reg rCountIsWr=0, _rCountIsWr=0; reg [3:0] rCountChnl=0, _rCountChnl=0; reg [C_TAG_WIDTH-1:0] rCountTag=0, _rCountTag=0; reg [9:0] rCount=0, _rCount=0; reg rCountDone=0, _rCountDone=0; reg rCountValid=0,_rCountValid=0; reg rCountStart=0, _rCountStart=0; reg rCountOdd32=0, _rCountOdd32=0; reg [9:0] rCountLen=0, _rCountLen=0; reg [C_NUM_CHNL-1:0] rWrDataRen=0, _rWrDataRen=0; reg rTxEngRdReqAck, _rTxEngRdReqAck; wire wRdReq; wire [3:0] wRdReqChnl; wire wWrReq; wire [3:0] wWrReqChnl; wire wRdAck; wire [3:0] wCountChnl; wire [11:0] wCountChnlShiftDW = (wCountChnl*C_PCI_DATA_WIDTH); // Mult can exceed 9 bits, so make this a wire wire [63:0] wRdAddr; wire [9:0] wRdLen; wire [1:0] wRdSgChnl; wire [63:0] wWrAddr; wire [9:0] wWrLen; wire [C_PCI_DATA_WIDTH-1:0] wWrData; reg [3:0] rRdChnl=0, _rRdChnl=0; reg [61:0] rRdAddr=62'd0, _rRdAddr=62'd0; reg [9:0] rRdLen=0, _rRdLen=0; reg [1:0] rRdSgChnl=0, _rRdSgChnl=0; reg [3:0] rWrChnl=0, _rWrChnl=0; reg [61:0] rWrAddr=62'd0, _rWrAddr=62'd0; reg [9:0] rWrLen=0, _rWrLen=0; reg [C_PCI_DATA_WIDTH-1:0] rWrData={C_PCI_DATA_WIDTH{1'd0}}, _rWrData={C_PCI_DATA_WIDTH{1'd0}}; assign wRdAddr = RD_ADDR[wRdReqChnl * `SIG_ADDR_W +: `SIG_ADDR_W]; assign wRdLen = RD_LEN[wRdReqChnl * `SIG_LEN_W +: `SIG_LEN_W]; assign wRdSgChnl = RD_SG_CHNL[wRdReqChnl * 2 +: 2]; assign wWrAddr = WR_ADDR[wWrReqChnl * `SIG_ADDR_W +: `SIG_ADDR_W]; assign wWrLen = WR_LEN[wWrReqChnl * `SIG_LEN_W +: `SIG_LEN_W]; assign wWrData = WR_DATA[wCountChnl * C_PCI_DATA_WIDTH +: C_PCI_DATA_WIDTH]; (* syn_encoding = "user" *) (* fsm_encoding = "user" *) reg [3:0] rCapState=`S_TXENGUPR64_CAP_RD_WR, _rCapState=`S_TXENGUPR64_CAP_RD_WR; reg [C_NUM_CHNL-1:0] rRdAck=0, _rRdAck=0; reg [C_NUM_CHNL-1:0] rWrAck=0, _rWrAck=0; reg rIsWr=0, _rIsWr=0; reg [5:0] rCapChnl=0, _rCapChnl=0; reg [61:0] rCapAddr=62'd0, _rCapAddr=62'd0; reg rCapAddr64=0, _rCapAddr64=0; reg [9:0] rCapLen=0, _rCapLen=0; reg rCapIsWr=0, _rCapIsWr=0; reg rExtTagReq=0, _rExtTagReq=0; reg [C_TAG_WIDTH-1:0] rExtTag=0, _rExtTag=0; reg [C_DATA_DELAY-1:0] rWnR=0, _rWnR=0; reg [(C_DATA_DELAY*4)-1:0] rChnl=0, _rChnl=0; reg [(C_DATA_DELAY*8)-1:0] rTag=0, _rTag=0; reg [(C_DATA_DELAY*62)-1:0] rAddr=0, _rAddr=0; reg [((C_DATA_DELAY+1)*10)-1:0] rLen=0, _rLen=0; reg [C_DATA_DELAY-1:0] rValid=0, _rValid=0; reg [C_DATA_DELAY-1:0] rDone=0, _rDone=0; reg [C_DATA_DELAY-1:0] rStart=0, _rStart=0; assign WR_DATA_REN = rWrDataRen; assign WR_ACK = rWrAck; assign RD_ACK = rRdAck; assign INT_TAG = {rRdSgChnl, rRdChnl}; assign INT_TAG_VALID = rExtTagReq; assign TX_ENG_RD_REQ_SENT = rTxEngRdReqAck; assign wRdAck = (wRdReq & EXT_TAG_VALID & RXBUF_SPACE_AVAIL); // Search for the next request so that we can move onto it immediately after // the current channel has released its request. tx_engine_selector #(.C_NUM_CHNL(C_NUM_CHNL)) selRd (.RST(RST_IN), .CLK(CLK), .REQ_ALL(RD_REQ), .REQ(wRdReq), .CHNL(wRdReqChnl)); tx_engine_selector #(.C_NUM_CHNL(C_NUM_CHNL)) selWr (.RST(RST_IN), .CLK(CLK), .REQ_ALL(WR_REQ), .REQ(wWrReq), .CHNL(wWrReqChnl)); // Buffer shift-selected channel request signals and FIFO data. always @ (posedge CLK) begin rRdChnl <= #1 _rRdChnl; rRdAddr <= #1 _rRdAddr; rRdLen <= #1 _rRdLen; rRdSgChnl <= #1 _rRdSgChnl; rWrChnl <= #1 _rWrChnl; rWrAddr <= #1 _rWrAddr; rWrLen <= #1 _rWrLen; rWrData <= #1 _rWrData; end always @ (*) begin _rRdChnl = wRdReqChnl; _rRdAddr = wRdAddr[63:2]; _rRdLen = wRdLen; _rRdSgChnl = wRdSgChnl; _rWrChnl = wWrReqChnl; _rWrAddr = wWrAddr[63:2]; _rWrLen = wWrLen; _rWrData = wWrData; end // Accept requests when the selector indicates. Capture the buffered // request parameters for hand-off to the formatting pipeline. Then // acknowledge the receipt to the channel so it can deassert the // request, and let the selector choose another channel. always @ (posedge CLK) begin rCapState <= #1 (RST_IN ? `S_TXENGUPR64_CAP_RD_WR : _rCapState); rRdAck <= #1 (RST_IN ? {C_NUM_CHNL{1'd0}} : _rRdAck); rWrAck <= #1 (RST_IN ? {C_NUM_CHNL{1'd0}} : _rWrAck); rIsWr <= #1 _rIsWr; rCapChnl <= #1 _rCapChnl; rCapAddr <= #1 _rCapAddr; rCapAddr64 <= #1 _rCapAddr64; rCapLen <= #1 _rCapLen; rCapIsWr <= #1 _rCapIsWr; rExtTagReq <= #1 _rExtTagReq; rExtTag <= #1 _rExtTag; rTxEngRdReqAck <= #1 _rTxEngRdReqAck; end always @ (*) begin _rCapState = rCapState; _rRdAck = rRdAck; _rWrAck = rWrAck; _rIsWr = rIsWr; _rCapChnl = rCapChnl; _rCapAddr = rCapAddr; _rCapAddr64 = (rCapAddr[61:30] != 0); _rCapLen = rCapLen; _rCapIsWr = rCapIsWr; _rExtTagReq = rExtTagReq; _rExtTag = rExtTag; _rTxEngRdReqAck = rTxEngRdReqAck; case (rCapState) `S_TXENGUPR64_CAP_RD_WR : begin _rIsWr = !wRdReq; _rRdAck = (wRdAck<<wRdReqChnl); _rTxEngRdReqAck = wRdAck; _rExtTagReq = wRdAck; _rCapState = (wRdAck ? `S_TXENGUPR64_CAP_CAP : `S_TXENGUPR64_CAP_WR_RD); end `S_TXENGUPR64_CAP_WR_RD : begin _rIsWr = wWrReq; _rWrAck = (wWrReq<<wWrReqChnl); _rCapState = (wWrReq ? `S_TXENGUPR64_CAP_CAP : `S_TXENGUPR64_CAP_RD_WR); end `S_TXENGUPR64_CAP_CAP : begin _rTxEngRdReqAck = 0; _rRdAck = 0; _rWrAck = 0; _rCapIsWr = rIsWr; _rExtTagReq = 0; _rExtTag = EXT_TAG; if (rIsWr) begin _rCapChnl = {2'd0, rWrChnl}; _rCapAddr = rWrAddr; _rCapLen = rWrLen; end else begin _rCapChnl = {rRdSgChnl, rRdChnl}; _rCapAddr = rRdAddr; _rCapLen = rRdLen; end _rCapState = `S_TXENGUPR64_CAP_REL; end `S_TXENGUPR64_CAP_REL : begin // Push into the formatting pipeline when ready if (TXR_META_READY & rMainState[0]) // S_TXENGUPR64_MAIN_IDLE _rCapState = (`S_TXENGUPR64_CAP_WR_RD>>(rCapIsWr)); // Changes to S_TXENGUPR64_CAP_RD_WR end default : begin _rCapState = `S_TXENGUPR64_CAP_RD_WR; end endcase end // Start the read/write when space is available in the output FIFO and when // request parameters have been captured (i.e. a pending request). always @ (posedge CLK) begin rMainState <= #1 (RST_IN ? `S_TXENGUPR64_MAIN_IDLE : _rMainState); rCountIsWr <= #1 _rCountIsWr; rCountLen <= #1 _rCountLen; rCount <= #1 _rCount; rCountDone <= #1 _rCountDone; rCountStart <= #1 _rCountStart; rCountChnl <= #1 _rCountChnl; rCountTag <= #1 _rCountTag; rCountOdd32 <= #1 _rCountOdd32; rWrDataRen <= #1 _rWrDataRen; rCountValid <= #1 RST_IN ? 0 : _rCountValid; end always @ (*) begin _rMainState = rMainState; _rCountIsWr = rCountIsWr; _rCount = rCount; _rCountLen = rCountLen; _rCountDone = rCountDone; _rCountStart = rCountStart; _rCountChnl = rCountChnl; _rCountTag = rCountTag; _rCountOdd32 = rCountOdd32; _rWrDataRen = rWrDataRen; _rCountStart = 0; _rCountValid = rCountValid; case (rMainState) `S_TXENGUPR64_MAIN_IDLE : begin _rCountIsWr = rCapIsWr; _rCountLen = rCapLen; _rCount = rCapLen; _rCountDone = (rCapLen <= 2'd2); _rCountChnl = rCapChnl[3:0]; _rCountTag = rExtTag; _rCountOdd32 = (rCapLen[0] & ((rCapAddr[61:30] == 0))); _rWrDataRen = ((TXR_META_READY & rCapState[3] & rCapIsWr)<<(rCapChnl[3:0])); // S_TXENGUPR64_CAP_REL _rCountStart = (TXR_META_READY & rCapState[3]); _rCountValid = TXR_META_READY & rCapState[3]; if (TXR_META_READY & rCapState[3]) // S_TXENGUPR64_CAP_REL _rMainState = (`S_TXENGUPR64_MAIN_RD<<(rCapIsWr)); // Change to S_TXENGUPR64_MAIN_WR; end `S_TXENGUPR64_MAIN_RD : begin _rMainState = `S_TXENGUPR64_MAIN_IDLE; end `S_TXENGUPR64_MAIN_WR : begin _rCount = rCount - 2'd2; _rCountDone = (rCount <= 3'd4); if (rCountDone) begin _rWrDataRen = 0; _rCountValid = 0; _rMainState = (rCountOdd32 ? `S_TXENGUPR64_MAIN_IDLE : `S_TXENGUPR64_MAIN_WAIT); end end `S_TXENGUPR64_MAIN_WAIT : begin // Signals request FIFO ren _rMainState = `S_TXENGUPR64_MAIN_IDLE; end default : begin _rMainState = `S_TXENGUPR64_MAIN_IDLE; end endcase end // Shift in the captured parameters and valid signal every cycle. // This pipeline will keep the formatter busy. assign wCountChnl = rChnl[(C_DATA_DELAY-2)*4 +:4]; always @ (posedge CLK) begin rWnR <= #1 _rWnR; rChnl <= #1 _rChnl; rTag <= #1 _rTag; rAddr <= #1 _rAddr; rLen <= #1 _rLen; rValid <= #1 _rValid; rDone <= #1 _rDone; rStart <= #1 _rStart; end always @ (*) begin _rWnR = {rWnR[((C_DATA_DELAY-1)*1)-1:0], rCapIsWr}; _rAddr = {rAddr[((C_DATA_DELAY-1)*62)-1:0], rCapAddr}; _rLen = {rLen[((C_DATA_DELAY-1)*10)-1:0], rCountLen}; _rChnl = {rChnl[((C_DATA_DELAY-1)*4)-1:0], rCountChnl}; _rTag = {rTag[((C_DATA_DELAY-1)*8)-1:0], (8'd0 | rCountTag)}; _rValid = {rValid[((C_DATA_DELAY-1)*1)-1:0], rCountValid & rCountIsWr}; // S_TXENGUPR64_MAIN_RD | S_TXENGUPR64_MAIN_WR _rDone = {rDone[((C_DATA_DELAY-1)*1)-1:0], rCountDone}; _rStart = {rStart[((C_DATA_DELAY-1)*1)-1:0], rCountStart}; end assign TXR_DATA = rWrData; assign TXR_DATA_VALID = rValid[(C_DATA_DELAY-1)*1 +:1]; assign TXR_DATA_START_FLAG = rStart[(C_DATA_DELAY-1)*1 +:1]; assign TXR_DATA_START_OFFSET = 0; assign TXR_DATA_END_FLAG = rDone[(C_DATA_DELAY-1)*1 +:1]; assign TXR_DATA_END_OFFSET = rLen[(C_DATA_DELAY-1)*10 +:`SIG_OFFSET_W] - 1; assign TXR_META_VALID = rCountStart; assign TXR_META_TYPE = rCapIsWr ? `TRLS_REQ_WR : `TRLS_REQ_RD; assign TXR_META_ADDR = {rCapAddr,2'b00}; assign TXR_META_LENGTH = rCapLen; assign TXR_META_LDWBE = rCapLen == 10'd1 ? 0 : 4'b1111; // TODO: This should be retimed assign TXR_META_FDWBE = 4'b1111; assign TXR_META_TAG = rCountTag; assign TXR_META_EP = 1'b0; assign TXR_META_ATTR = 3'b110; assign TXR_META_TC = 0; endmodule
(** Extraction : tests of optimizations of pattern matching *) (** First, a few basic tests *) Definition test1 b := match b with | true => true | false => false end. Extraction test1. (** should be seen as the identity *) Definition test2 b := match b with | true => false | false => false end. Extraction test2. (** should be seen a the always-false constant function *) Inductive hole (A:Set) : Set := Hole | Hole2. Definition wrong_id (A B : Set) (x:hole A) : hole B := match x with | Hole => @Hole _ | Hole2 => @Hole2 _ end. Extraction wrong_id. (** should _not_ be optimized as an identity *) Definition test3 (A:Type)(o : option A) := match o with | Some x => Some x | None => None end. Extraction test3. (** Even with type parameters, should be seen as identity *) Inductive indu : Type := A : nat -> indu | B | C. Definition test4 n := match n with | A m => A (S m) | B => B | C => C end. Extraction test4. (** should merge branchs B C into a x->x *) Definition test5 n := match n with | A m => A (S m) | B => B | C => B end. Extraction test5. (** should merge branches B C into _->B *) Inductive indu' : Type := A' : nat -> indu' | B' | C' | D' | E' | F'. Definition test6 n := match n with | A' m => A' (S m) | B' => C' | C' => C' | D' => C' | E' => B' | F' => B' end. Extraction test6. (** should merge some branches into a _->C' *) (** NB : In Coq, "| a => a" corresponds to n, hence some "| _ -> n" are extracted *) Definition test7 n := match n with | A m => Some m | B => None | C => None end. Extraction test7. (** should merge branches B,C into a _->None *) (** Script from bug #2413 *) Set Implicit Arguments. Section S. Definition message := nat. Definition word := nat. Definition mode := nat. Definition opcode := nat. Variable condition : word -> option opcode. Section decoder_result. Variable inst : Type. Inductive decoder_result : Type := | DecUndefined : decoder_result | DecUnpredictable : decoder_result | DecInst : inst -> decoder_result | DecError : message -> decoder_result. End decoder_result. Definition decode_cond_mode (mode : Type) (f : word -> decoder_result mode) (w : word) (inst : Type) (g : mode -> opcode -> inst) : decoder_result inst := match condition w with | Some oc => match f w with | DecInst i => DecInst (g i oc) | DecError m => @DecError inst m | DecUndefined => @DecUndefined inst | DecUnpredictable => @DecUnpredictable inst end | None => @DecUndefined inst end. End S. Extraction decode_cond_mode. (** inner match should not be factorized with a partial x->x (different type) *)
(** Extraction : tests of optimizations of pattern matching *) (** First, a few basic tests *) Definition test1 b := match b with | true => true | false => false end. Extraction test1. (** should be seen as the identity *) Definition test2 b := match b with | true => false | false => false end. Extraction test2. (** should be seen a the always-false constant function *) Inductive hole (A:Set) : Set := Hole | Hole2. Definition wrong_id (A B : Set) (x:hole A) : hole B := match x with | Hole => @Hole _ | Hole2 => @Hole2 _ end. Extraction wrong_id. (** should _not_ be optimized as an identity *) Definition test3 (A:Type)(o : option A) := match o with | Some x => Some x | None => None end. Extraction test3. (** Even with type parameters, should be seen as identity *) Inductive indu : Type := A : nat -> indu | B | C. Definition test4 n := match n with | A m => A (S m) | B => B | C => C end. Extraction test4. (** should merge branchs B C into a x->x *) Definition test5 n := match n with | A m => A (S m) | B => B | C => B end. Extraction test5. (** should merge branches B C into _->B *) Inductive indu' : Type := A' : nat -> indu' | B' | C' | D' | E' | F'. Definition test6 n := match n with | A' m => A' (S m) | B' => C' | C' => C' | D' => C' | E' => B' | F' => B' end. Extraction test6. (** should merge some branches into a _->C' *) (** NB : In Coq, "| a => a" corresponds to n, hence some "| _ -> n" are extracted *) Definition test7 n := match n with | A m => Some m | B => None | C => None end. Extraction test7. (** should merge branches B,C into a _->None *) (** Script from bug #2413 *) Set Implicit Arguments. Section S. Definition message := nat. Definition word := nat. Definition mode := nat. Definition opcode := nat. Variable condition : word -> option opcode. Section decoder_result. Variable inst : Type. Inductive decoder_result : Type := | DecUndefined : decoder_result | DecUnpredictable : decoder_result | DecInst : inst -> decoder_result | DecError : message -> decoder_result. End decoder_result. Definition decode_cond_mode (mode : Type) (f : word -> decoder_result mode) (w : word) (inst : Type) (g : mode -> opcode -> inst) : decoder_result inst := match condition w with | Some oc => match f w with | DecInst i => DecInst (g i oc) | DecError m => @DecError inst m | DecUndefined => @DecUndefined inst | DecUnpredictable => @DecUnpredictable inst end | None => @DecUndefined inst end. End S. Extraction decode_cond_mode. (** inner match should not be factorized with a partial x->x (different type) *)
(** Extraction : tests of optimizations of pattern matching *) (** First, a few basic tests *) Definition test1 b := match b with | true => true | false => false end. Extraction test1. (** should be seen as the identity *) Definition test2 b := match b with | true => false | false => false end. Extraction test2. (** should be seen a the always-false constant function *) Inductive hole (A:Set) : Set := Hole | Hole2. Definition wrong_id (A B : Set) (x:hole A) : hole B := match x with | Hole => @Hole _ | Hole2 => @Hole2 _ end. Extraction wrong_id. (** should _not_ be optimized as an identity *) Definition test3 (A:Type)(o : option A) := match o with | Some x => Some x | None => None end. Extraction test3. (** Even with type parameters, should be seen as identity *) Inductive indu : Type := A : nat -> indu | B | C. Definition test4 n := match n with | A m => A (S m) | B => B | C => C end. Extraction test4. (** should merge branchs B C into a x->x *) Definition test5 n := match n with | A m => A (S m) | B => B | C => B end. Extraction test5. (** should merge branches B C into _->B *) Inductive indu' : Type := A' : nat -> indu' | B' | C' | D' | E' | F'. Definition test6 n := match n with | A' m => A' (S m) | B' => C' | C' => C' | D' => C' | E' => B' | F' => B' end. Extraction test6. (** should merge some branches into a _->C' *) (** NB : In Coq, "| a => a" corresponds to n, hence some "| _ -> n" are extracted *) Definition test7 n := match n with | A m => Some m | B => None | C => None end. Extraction test7. (** should merge branches B,C into a _->None *) (** Script from bug #2413 *) Set Implicit Arguments. Section S. Definition message := nat. Definition word := nat. Definition mode := nat. Definition opcode := nat. Variable condition : word -> option opcode. Section decoder_result. Variable inst : Type. Inductive decoder_result : Type := | DecUndefined : decoder_result | DecUnpredictable : decoder_result | DecInst : inst -> decoder_result | DecError : message -> decoder_result. End decoder_result. Definition decode_cond_mode (mode : Type) (f : word -> decoder_result mode) (w : word) (inst : Type) (g : mode -> opcode -> inst) : decoder_result inst := match condition w with | Some oc => match f w with | DecInst i => DecInst (g i oc) | DecError m => @DecError inst m | DecUndefined => @DecUndefined inst | DecUnpredictable => @DecUnpredictable inst end | None => @DecUndefined inst end. End S. Extraction decode_cond_mode. (** inner match should not be factorized with a partial x->x (different type) *)
(** Extraction : tests of optimizations of pattern matching *) (** First, a few basic tests *) Definition test1 b := match b with | true => true | false => false end. Extraction test1. (** should be seen as the identity *) Definition test2 b := match b with | true => false | false => false end. Extraction test2. (** should be seen a the always-false constant function *) Inductive hole (A:Set) : Set := Hole | Hole2. Definition wrong_id (A B : Set) (x:hole A) : hole B := match x with | Hole => @Hole _ | Hole2 => @Hole2 _ end. Extraction wrong_id. (** should _not_ be optimized as an identity *) Definition test3 (A:Type)(o : option A) := match o with | Some x => Some x | None => None end. Extraction test3. (** Even with type parameters, should be seen as identity *) Inductive indu : Type := A : nat -> indu | B | C. Definition test4 n := match n with | A m => A (S m) | B => B | C => C end. Extraction test4. (** should merge branchs B C into a x->x *) Definition test5 n := match n with | A m => A (S m) | B => B | C => B end. Extraction test5. (** should merge branches B C into _->B *) Inductive indu' : Type := A' : nat -> indu' | B' | C' | D' | E' | F'. Definition test6 n := match n with | A' m => A' (S m) | B' => C' | C' => C' | D' => C' | E' => B' | F' => B' end. Extraction test6. (** should merge some branches into a _->C' *) (** NB : In Coq, "| a => a" corresponds to n, hence some "| _ -> n" are extracted *) Definition test7 n := match n with | A m => Some m | B => None | C => None end. Extraction test7. (** should merge branches B,C into a _->None *) (** Script from bug #2413 *) Set Implicit Arguments. Section S. Definition message := nat. Definition word := nat. Definition mode := nat. Definition opcode := nat. Variable condition : word -> option opcode. Section decoder_result. Variable inst : Type. Inductive decoder_result : Type := | DecUndefined : decoder_result | DecUnpredictable : decoder_result | DecInst : inst -> decoder_result | DecError : message -> decoder_result. End decoder_result. Definition decode_cond_mode (mode : Type) (f : word -> decoder_result mode) (w : word) (inst : Type) (g : mode -> opcode -> inst) : decoder_result inst := match condition w with | Some oc => match f w with | DecInst i => DecInst (g i oc) | DecError m => @DecError inst m | DecUndefined => @DecUndefined inst | DecUnpredictable => @DecUnpredictable inst end | None => @DecUndefined inst end. End S. Extraction decode_cond_mode. (** inner match should not be factorized with a partial x->x (different type) *)
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * 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. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // 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 REGENTS OF THE // UNIVERSITY OF CALIFORNIA 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. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: offset_flag_to_one_hot.v // Version: 1.0 // Verilog Standard: Verilog-2001 // Description: The offset_flag_to_one_hot module takes a data offset, // and offset_enable and computes the 1-hot encoding of the offset when enabled // Author: Dustin Richmond (@darichmond) //----------------------------------------------------------------------------- `timescale 1ns/1ns `include "trellis.vh" module offset_flag_to_one_hot #( parameter C_WIDTH = 4 ) ( input [clog2s(C_WIDTH)-1:0] WR_OFFSET, input WR_FLAG, output [C_WIDTH-1:0] RD_ONE_HOT ); assign RD_ONE_HOT = {{(C_WIDTH-1){1'b0}},WR_FLAG} << WR_OFFSET; endmodule
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * 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. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // 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 REGENTS OF THE // UNIVERSITY OF CALIFORNIA 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. // ---------------------------------------------------------------------- module reset_extender #(parameter C_RST_COUNT = 10) (input CLK, input RST_BUS, input RST_LOGIC, output RST_OUT, output PENDING_RST); localparam C_CLOG2_RST_COUNT = clog2s(C_RST_COUNT); localparam C_CEIL2_RST_COUNT = 1 << C_CLOG2_RST_COUNT; localparam C_RST_SHIFTREG_DEPTH = 4; wire [C_CLOG2_RST_COUNT:0] wRstCount; wire [C_RST_SHIFTREG_DEPTH:0] wRstShiftReg; assign PENDING_RST = wRstShiftReg != 0; assign RST_OUT = wRstShiftReg[C_RST_SHIFTREG_DEPTH]; counter #(// Parameters .C_MAX_VALUE (C_CEIL2_RST_COUNT), .C_SAT_VALUE (C_CEIL2_RST_COUNT), .C_RST_VALUE (C_CEIL2_RST_COUNT - C_RST_COUNT) /*AUTOINSTPARAM*/) rst_counter (// Outputs .VALUE (wRstCount), // Inputs .ENABLE (1'b1), .RST_IN (RST_BUS | RST_LOGIC), /*AUTOINST*/ // Inputs .CLK (CLK)); shiftreg #(// Parameters .C_DEPTH (C_RST_SHIFTREG_DEPTH), .C_WIDTH (1), .C_VALUE (0) /*AUTOINSTPARAM*/) rst_shiftreg (// Outputs .RD_DATA (wRstShiftReg), // Inputs .RST_IN (0), .WR_DATA (~wRstCount[C_CLOG2_RST_COUNT]), /*AUTOINST*/ // Inputs .CLK (CLK)); endmodule
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * 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. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // 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 REGENTS OF THE // UNIVERSITY OF CALIFORNIA 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. // ---------------------------------------------------------------------- module reset_extender #(parameter C_RST_COUNT = 10) (input CLK, input RST_BUS, input RST_LOGIC, output RST_OUT, output PENDING_RST); localparam C_CLOG2_RST_COUNT = clog2s(C_RST_COUNT); localparam C_CEIL2_RST_COUNT = 1 << C_CLOG2_RST_COUNT; localparam C_RST_SHIFTREG_DEPTH = 4; wire [C_CLOG2_RST_COUNT:0] wRstCount; wire [C_RST_SHIFTREG_DEPTH:0] wRstShiftReg; assign PENDING_RST = wRstShiftReg != 0; assign RST_OUT = wRstShiftReg[C_RST_SHIFTREG_DEPTH]; counter #(// Parameters .C_MAX_VALUE (C_CEIL2_RST_COUNT), .C_SAT_VALUE (C_CEIL2_RST_COUNT), .C_RST_VALUE (C_CEIL2_RST_COUNT - C_RST_COUNT) /*AUTOINSTPARAM*/) rst_counter (// Outputs .VALUE (wRstCount), // Inputs .ENABLE (1'b1), .RST_IN (RST_BUS | RST_LOGIC), /*AUTOINST*/ // Inputs .CLK (CLK)); shiftreg #(// Parameters .C_DEPTH (C_RST_SHIFTREG_DEPTH), .C_WIDTH (1), .C_VALUE (0) /*AUTOINSTPARAM*/) rst_shiftreg (// Outputs .RD_DATA (wRstShiftReg), // Inputs .RST_IN (0), .WR_DATA (~wRstCount[C_CLOG2_RST_COUNT]), /*AUTOINST*/ // Inputs .CLK (CLK)); endmodule
(************************************************************************) (* v * The Coq Proof Assistant / The Coq Development Team *) (* <O___,, * INRIA - CNRS - LIX - LRI - PPS - Copyright 1999-2015 *) (* \VV/ **************************************************************) (* // * This file is distributed under the terms of the *) (* * GNU Lesser General Public License Version 2.1 *) (************************************************************************) Require Import ZAxioms ZMulOrder ZSgnAbs NZDiv. (** * Euclidean Division for integers, Euclid convention We use here the "usual" formulation of the Euclid Theorem [forall a b, b<>0 -> exists b q, a = b*q+r /\ 0 < r < |b| ] The outcome of the modulo function is hence always positive. This corresponds to convention "E" in the following paper: R. Boute, "The Euclidean definition of the functions div and mod", ACM Transactions on Programming Languages and Systems, Vol. 14, No.2, pp. 127-144, April 1992. See files [ZDivTrunc] and [ZDivFloor] for others conventions. We simply extend NZDiv with a bound for modulo that holds regardless of the sign of a and b. This new specification subsume mod_bound_pos, which nonetheless stays there for subtyping. Note also that ZAxiomSig now already contain a div and a modulo (that follow the Floor convention). We just ignore them here. *) Module Type EuclidSpec (Import A : ZAxiomsSig')(Import B : DivMod' A). Axiom mod_always_pos : forall a b, b ~= 0 -> 0 <= a mod b < abs b. End EuclidSpec. Module Type ZEuclid (Z:ZAxiomsSig) := NZDiv.NZDiv Z <+ EuclidSpec Z. Module Type ZEuclid' (Z:ZAxiomsSig) := NZDiv.NZDiv' Z <+ EuclidSpec Z. Module ZEuclidProp (Import A : ZAxiomsSig') (Import B : ZMulOrderProp A) (Import C : ZSgnAbsProp A B) (Import D : ZEuclid' A). Module Import Private_NZDiv := Nop <+ NZDivProp A D B. (** Another formulation of the main equation *) Lemma mod_eq : forall a b, b~=0 -> a mod b == a - b*(a/b). Proof. intros. rewrite <- add_move_l. symmetry. now apply div_mod. Qed. Ltac pos_or_neg a := let LT := fresh "LT" in let LE := fresh "LE" in destruct (le_gt_cases 0 a) as [LE|LT]; [|rewrite <- opp_pos_neg in LT]. (** Uniqueness theorems *) Theorem div_mod_unique : forall b q1 q2 r1 r2 : t, 0<=r1<abs b -> 0<=r2<abs b -> b*q1+r1 == b*q2+r2 -> q1 == q2 /\ r1 == r2. Proof. intros b q1 q2 r1 r2 Hr1 Hr2 EQ. pos_or_neg b. rewrite abs_eq in * by trivial. apply div_mod_unique with b; trivial. rewrite abs_neq' in * by auto using lt_le_incl. rewrite eq_sym_iff. apply div_mod_unique with (-b); trivial. rewrite 2 mul_opp_l. rewrite add_move_l, sub_opp_r. rewrite <-add_assoc. symmetry. rewrite add_move_l, sub_opp_r. now rewrite (add_comm r2), (add_comm r1). Qed. Theorem div_unique: forall a b q r, 0<=r<abs b -> a == b*q + r -> q == a/b. Proof. intros a b q r Hr EQ. assert (Hb : b~=0). pos_or_neg b. rewrite abs_eq in Hr; intuition; order. rewrite <- opp_0, eq_opp_r. rewrite abs_neq' in Hr; intuition; order. destruct (div_mod_unique b q (a/b) r (a mod b)); trivial. now apply mod_always_pos. now rewrite <- div_mod. Qed. Theorem mod_unique: forall a b q r, 0<=r<abs b -> a == b*q + r -> r == a mod b. Proof. intros a b q r Hr EQ. assert (Hb : b~=0). pos_or_neg b. rewrite abs_eq in Hr; intuition; order. rewrite <- opp_0, eq_opp_r. rewrite abs_neq' in Hr; intuition; order. destruct (div_mod_unique b q (a/b) r (a mod b)); trivial. now apply mod_always_pos. now rewrite <- div_mod. Qed. (** Sign rules *) Lemma div_opp_r : forall a b, b~=0 -> a/(-b) == -(a/b). Proof. intros. symmetry. apply div_unique with (a mod b). rewrite abs_opp; now apply mod_always_pos. rewrite mul_opp_opp; now apply div_mod. Qed. Lemma mod_opp_r : forall a b, b~=0 -> a mod (-b) == a mod b. Proof. intros. symmetry. apply mod_unique with (-(a/b)). rewrite abs_opp; now apply mod_always_pos. rewrite mul_opp_opp; now apply div_mod. Qed. Lemma div_opp_l_z : forall a b, b~=0 -> a mod b == 0 -> (-a)/b == -(a/b). Proof. intros a b Hb Hab. symmetry. apply div_unique with (-(a mod b)). rewrite Hab, opp_0. split; [order|]. pos_or_neg b; [rewrite abs_eq | rewrite abs_neq']; order. now rewrite mul_opp_r, <-opp_add_distr, <-div_mod. Qed. Lemma div_opp_l_nz : forall a b, b~=0 -> a mod b ~= 0 -> (-a)/b == -(a/b)-sgn b. Proof. intros a b Hb Hab. symmetry. apply div_unique with (abs b -(a mod b)). rewrite lt_sub_lt_add_l. rewrite <- le_add_le_sub_l. nzsimpl. rewrite <- (add_0_l (abs b)) at 2. rewrite <- add_lt_mono_r. destruct (mod_always_pos a b); intuition order. rewrite <- 2 add_opp_r, mul_add_distr_l, 2 mul_opp_r. rewrite sgn_abs. rewrite add_shuffle2, add_opp_diag_l; nzsimpl. rewrite <-opp_add_distr, <-div_mod; order. Qed. Lemma mod_opp_l_z : forall a b, b~=0 -> a mod b == 0 -> (-a) mod b == 0. Proof. intros a b Hb Hab. symmetry. apply mod_unique with (-(a/b)). split; [order|now rewrite abs_pos]. now rewrite <-opp_0, <-Hab, mul_opp_r, <-opp_add_distr, <-div_mod. Qed. Lemma mod_opp_l_nz : forall a b, b~=0 -> a mod b ~= 0 -> (-a) mod b == abs b - (a mod b). Proof. intros a b Hb Hab. symmetry. apply mod_unique with (-(a/b)-sgn b). rewrite lt_sub_lt_add_l. rewrite <- le_add_le_sub_l. nzsimpl. rewrite <- (add_0_l (abs b)) at 2. rewrite <- add_lt_mono_r. destruct (mod_always_pos a b); intuition order. rewrite <- 2 add_opp_r, mul_add_distr_l, 2 mul_opp_r. rewrite sgn_abs. rewrite add_shuffle2, add_opp_diag_l; nzsimpl. rewrite <-opp_add_distr, <-div_mod; order. Qed. Lemma div_opp_opp_z : forall a b, b~=0 -> a mod b == 0 -> (-a)/(-b) == a/b. Proof. intros. now rewrite div_opp_r, div_opp_l_z, opp_involutive. Qed. Lemma div_opp_opp_nz : forall a b, b~=0 -> a mod b ~= 0 -> (-a)/(-b) == a/b + sgn(b). Proof. intros. rewrite div_opp_r, div_opp_l_nz by trivial. now rewrite opp_sub_distr, opp_involutive. Qed. Lemma mod_opp_opp_z : forall a b, b~=0 -> a mod b == 0 -> (-a) mod (-b) == 0. Proof. intros. now rewrite mod_opp_r, mod_opp_l_z. Qed. Lemma mod_opp_opp_nz : forall a b, b~=0 -> a mod b ~= 0 -> (-a) mod (-b) == abs b - a mod b. Proof. intros. now rewrite mod_opp_r, mod_opp_l_nz. Qed. (** A division by itself returns 1 *) Lemma div_same : forall a, a~=0 -> a/a == 1. Proof. intros. symmetry. apply div_unique with 0. split; [order|now rewrite abs_pos]. now nzsimpl. Qed. Lemma mod_same : forall a, a~=0 -> a mod a == 0. Proof. intros. rewrite mod_eq, div_same by trivial. nzsimpl. apply sub_diag. Qed. (** A division of a small number by a bigger one yields zero. *) Theorem div_small: forall a b, 0<=a<b -> a/b == 0. Proof. exact div_small. Qed. (** Same situation, in term of modulo: *) Theorem mod_small: forall a b, 0<=a<b -> a mod b == a. Proof. exact mod_small. Qed. (** * Basic values of divisions and modulo. *) Lemma div_0_l: forall a, a~=0 -> 0/a == 0. Proof. intros. pos_or_neg a. apply div_0_l; order. apply opp_inj. rewrite <- div_opp_r, opp_0 by trivial. now apply div_0_l. Qed. Lemma mod_0_l: forall a, a~=0 -> 0 mod a == 0. Proof. intros; rewrite mod_eq, div_0_l; now nzsimpl. Qed. Lemma div_1_r: forall a, a/1 == a. Proof. intros. symmetry. apply div_unique with 0. assert (H:=lt_0_1); rewrite abs_pos; intuition; order. now nzsimpl. Qed. Lemma mod_1_r: forall a, a mod 1 == 0. Proof. intros. rewrite mod_eq, div_1_r; nzsimpl; auto using sub_diag. apply neq_sym, lt_neq; apply lt_0_1. Qed. Lemma div_1_l: forall a, 1<a -> 1/a == 0. Proof. exact div_1_l. Qed. Lemma mod_1_l: forall a, 1<a -> 1 mod a == 1. Proof. exact mod_1_l. Qed. Lemma div_mul : forall a b, b~=0 -> (a*b)/b == a. Proof. intros. symmetry. apply div_unique with 0. split; [order|now rewrite abs_pos]. nzsimpl; apply mul_comm. Qed. Lemma mod_mul : forall a b, b~=0 -> (a*b) mod b == 0. Proof. intros. rewrite mod_eq, div_mul by trivial. rewrite mul_comm; apply sub_diag. Qed. Theorem div_unique_exact a b q: b~=0 -> a == b*q -> q == a/b. Proof. intros Hb H. rewrite H, mul_comm. symmetry. now apply div_mul. Qed. (** * Order results about mod and div *) (** A modulo cannot grow beyond its starting point. *) Theorem mod_le: forall a b, 0<=a -> b~=0 -> a mod b <= a. Proof. intros. pos_or_neg b. apply mod_le; order. rewrite <- mod_opp_r by trivial. apply mod_le; order. Qed. Theorem div_pos : forall a b, 0<=a -> 0<b -> 0<= a/b. Proof. exact div_pos. Qed. Lemma div_str_pos : forall a b, 0<b<=a -> 0 < a/b. Proof. exact div_str_pos. Qed. Lemma div_small_iff : forall a b, b~=0 -> (a/b==0 <-> 0<=a<abs b). Proof. intros a b Hb. split. intros EQ. rewrite (div_mod a b Hb), EQ; nzsimpl. now apply mod_always_pos. intros. pos_or_neg b. apply div_small. now rewrite <- (abs_eq b). apply opp_inj; rewrite opp_0, <- div_opp_r by trivial. apply div_small. rewrite <- (abs_neq' b) by order. trivial. Qed. Lemma mod_small_iff : forall a b, b~=0 -> (a mod b == a <-> 0<=a<abs b). Proof. intros. rewrite <- div_small_iff, mod_eq by trivial. rewrite sub_move_r, <- (add_0_r a) at 1. rewrite add_cancel_l. rewrite eq_sym_iff, eq_mul_0. tauto. Qed. (** As soon as the divisor is strictly greater than 1, the division is strictly decreasing. *) Lemma div_lt : forall a b, 0<a -> 1<b -> a/b < a. Proof. exact div_lt. Qed. (** [le] is compatible with a positive division. *) Lemma div_le_mono : forall a b c, 0<c -> a<=b -> a/c <= b/c. Proof. intros a b c Hc Hab. rewrite lt_eq_cases in Hab. destruct Hab as [LT|EQ]; [|rewrite EQ; order]. rewrite <- lt_succ_r. rewrite (mul_lt_mono_pos_l c) by order. nzsimpl. rewrite (add_lt_mono_r _ _ (a mod c)). rewrite <- div_mod by order. apply lt_le_trans with b; trivial. rewrite (div_mod b c) at 1 by order. rewrite <- add_assoc, <- add_le_mono_l. apply le_trans with (c+0). nzsimpl; destruct (mod_always_pos b c); try order. rewrite abs_eq in *; order. rewrite <- add_le_mono_l. destruct (mod_always_pos a c); order. Qed. (** In this convention, [div] performs Rounding-Toward-Bottom when divisor is positive, and Rounding-Toward-Top otherwise. Since we cannot speak of rational values here, we express this fact by multiplying back by [b], and this leads to a nice unique statement. *) Lemma mul_div_le : forall a b, b~=0 -> b*(a/b) <= a. Proof. intros. rewrite (div_mod a b) at 2; trivial. rewrite <- (add_0_r (b*(a/b))) at 1. rewrite <- add_le_mono_l. now destruct (mod_always_pos a b). Qed. (** Giving a reversed bound is slightly more complex *) Lemma mul_succ_div_gt: forall a b, 0<b -> a < b*(S (a/b)). Proof. intros. nzsimpl. rewrite (div_mod a b) at 1; try order. rewrite <- add_lt_mono_l. destruct (mod_always_pos a b). order. rewrite abs_eq in *; order. Qed. Lemma mul_pred_div_gt: forall a b, b<0 -> a < b*(P (a/b)). Proof. intros a b Hb. rewrite mul_pred_r, <- add_opp_r. rewrite (div_mod a b) at 1; try order. rewrite <- add_lt_mono_l. destruct (mod_always_pos a b). order. rewrite <- opp_pos_neg in Hb. rewrite abs_neq' in *; order. Qed. (** NB: The three previous properties could be used as specifications for [div]. *) (** Inequality [mul_div_le] is exact iff the modulo is zero. *) Lemma div_exact : forall a b, b~=0 -> (a == b*(a/b) <-> a mod b == 0). Proof. intros. rewrite (div_mod a b) at 1; try order. rewrite <- (add_0_r (b*(a/b))) at 2. apply add_cancel_l. Qed. (** Some additionnal inequalities about div. *) Theorem div_lt_upper_bound: forall a b q, 0<b -> a < b*q -> a/b < q. Proof. intros. rewrite (mul_lt_mono_pos_l b) by trivial. apply le_lt_trans with a; trivial. apply mul_div_le; order. Qed. Theorem div_le_upper_bound: forall a b q, 0<b -> a <= b*q -> a/b <= q. Proof. intros. rewrite <- (div_mul q b) by order. apply div_le_mono; trivial. now rewrite mul_comm. Qed. Theorem div_le_lower_bound: forall a b q, 0<b -> b*q <= a -> q <= a/b. Proof. intros. rewrite <- (div_mul q b) by order. apply div_le_mono; trivial. now rewrite mul_comm. Qed. (** A division respects opposite monotonicity for the divisor *) Lemma div_le_compat_l: forall p q r, 0<=p -> 0<q<=r -> p/r <= p/q. Proof. exact div_le_compat_l. Qed. (** * Relations between usual operations and mod and div *) Lemma mod_add : forall a b c, c~=0 -> (a + b * c) mod c == a mod c. Proof. intros. symmetry. apply mod_unique with (a/c+b); trivial. now apply mod_always_pos. rewrite mul_add_distr_l, add_shuffle0, <- div_mod by order. now rewrite mul_comm. Qed. Lemma div_add : forall a b c, c~=0 -> (a + b * c) / c == a / c + b. Proof. intros. apply (mul_cancel_l _ _ c); try order. apply (add_cancel_r _ _ ((a+b*c) mod c)). rewrite <- div_mod, mod_add by order. rewrite mul_add_distr_l, add_shuffle0, <- div_mod by order. now rewrite mul_comm. Qed. Lemma div_add_l: forall a b c, b~=0 -> (a * b + c) / b == a + c / b. Proof. intros a b c. rewrite (add_comm _ c), (add_comm a). now apply div_add. Qed. (** Cancellations. *) (** With the current convention, the following isn't always true when [c<0]: [-3*-1 / -2*-1 = 3/2 = 1] while [-3/-2 = 2] *) Lemma div_mul_cancel_r : forall a b c, b~=0 -> 0<c -> (a*c)/(b*c) == a/b. Proof. intros. symmetry. apply div_unique with ((a mod b)*c). (* ineqs *) rewrite abs_mul, (abs_eq c) by order. rewrite <-(mul_0_l c), <-mul_lt_mono_pos_r, <-mul_le_mono_pos_r by trivial. now apply mod_always_pos. (* equation *) rewrite (div_mod a b) at 1 by order. rewrite mul_add_distr_r. rewrite add_cancel_r. rewrite <- 2 mul_assoc. now rewrite (mul_comm c). Qed. Lemma div_mul_cancel_l : forall a b c, b~=0 -> 0<c -> (c*a)/(c*b) == a/b. Proof. intros. rewrite !(mul_comm c); now apply div_mul_cancel_r. Qed. Lemma mul_mod_distr_l: forall a b c, b~=0 -> 0<c -> (c*a) mod (c*b) == c * (a mod b). Proof. intros. rewrite <- (add_cancel_l _ _ ((c*b)* ((c*a)/(c*b)))). rewrite <- div_mod. rewrite div_mul_cancel_l by trivial. rewrite <- mul_assoc, <- mul_add_distr_l, mul_cancel_l by order. apply div_mod; order. rewrite <- neq_mul_0; intuition; order. Qed. Lemma mul_mod_distr_r: forall a b c, b~=0 -> 0<c -> (a*c) mod (b*c) == (a mod b) * c. Proof. intros. rewrite !(mul_comm _ c); now rewrite mul_mod_distr_l. Qed. (** Operations modulo. *) Theorem mod_mod: forall a n, n~=0 -> (a mod n) mod n == a mod n. Proof. intros. rewrite mod_small_iff by trivial. now apply mod_always_pos. Qed. Lemma mul_mod_idemp_l : forall a b n, n~=0 -> ((a mod n)*b) mod n == (a*b) mod n. Proof. intros a b n Hn. symmetry. rewrite (div_mod a n) at 1 by order. rewrite add_comm, (mul_comm n), (mul_comm _ b). rewrite mul_add_distr_l, mul_assoc. rewrite mod_add by trivial. now rewrite mul_comm. Qed. Lemma mul_mod_idemp_r : forall a b n, n~=0 -> (a*(b mod n)) mod n == (a*b) mod n. Proof. intros. rewrite !(mul_comm a). now apply mul_mod_idemp_l. Qed. Theorem mul_mod: forall a b n, n~=0 -> (a * b) mod n == ((a mod n) * (b mod n)) mod n. Proof. intros. now rewrite mul_mod_idemp_l, mul_mod_idemp_r. Qed. Lemma add_mod_idemp_l : forall a b n, n~=0 -> ((a mod n)+b) mod n == (a+b) mod n. Proof. intros a b n Hn. symmetry. rewrite (div_mod a n) at 1 by order. rewrite <- add_assoc, add_comm, mul_comm. now rewrite mod_add. Qed. Lemma add_mod_idemp_r : forall a b n, n~=0 -> (a+(b mod n)) mod n == (a+b) mod n. Proof. intros. rewrite !(add_comm a). now apply add_mod_idemp_l. Qed. Theorem add_mod: forall a b n, n~=0 -> (a+b) mod n == (a mod n + b mod n) mod n. Proof. intros. now rewrite add_mod_idemp_l, add_mod_idemp_r. Qed. (** With the current convention, the following result isn't always true with a negative intermediate divisor. For instance [ 3/(-2)/(-2) = 1 <> 0 = 3 / (-2*-2) ] and [ 3/(-2)/2 = -1 <> 0 = 3 / (-2*2) ]. *) Lemma div_div : forall a b c, 0<b -> c~=0 -> (a/b)/c == a/(b*c). Proof. intros a b c Hb Hc. apply div_unique with (b*((a/b) mod c) + a mod b). (* begin 0<= ... <abs(b*c) *) rewrite abs_mul. destruct (mod_always_pos (a/b) c), (mod_always_pos a b); try order. split. apply add_nonneg_nonneg; trivial. apply mul_nonneg_nonneg; order. apply lt_le_trans with (b*((a/b) mod c) + abs b). now rewrite <- add_lt_mono_l. rewrite (abs_eq b) by order. now rewrite <- mul_succ_r, <- mul_le_mono_pos_l, le_succ_l. (* end 0<= ... < abs(b*c) *) rewrite (div_mod a b) at 1 by order. rewrite add_assoc, add_cancel_r. rewrite <- mul_assoc, <- mul_add_distr_l, mul_cancel_l by order. apply div_mod; order. Qed. (** Similarly, the following result doesn't always hold when [b<0]. For instance [3 mod (-2*-2)) = 3] while [3 mod (-2) + (-2)*((3/-2) mod -2) = -1]. *) Lemma mod_mul_r : forall a b c, 0<b -> c~=0 -> a mod (b*c) == a mod b + b*((a/b) mod c). Proof. intros a b c Hb Hc. apply add_cancel_l with (b*c*(a/(b*c))). rewrite <- div_mod by (apply neq_mul_0; split; order). rewrite <- div_div by trivial. rewrite add_assoc, add_shuffle0, <- mul_assoc, <- mul_add_distr_l. rewrite <- div_mod by order. apply div_mod; order. Qed. (** A last inequality: *) Theorem div_mul_le: forall a b c, 0<=a -> 0<b -> 0<=c -> c*(a/b) <= (c*a)/b. Proof. exact div_mul_le. Qed. (** mod is related to divisibility *) Lemma mod_divides : forall a b, b~=0 -> (a mod b == 0 <-> (b|a)). Proof. intros a b Hb. split. intros Hab. exists (a/b). rewrite mul_comm. rewrite (div_mod a b Hb) at 1. rewrite Hab; now nzsimpl. intros (c,Hc). rewrite Hc. now apply mod_mul. Qed. End ZEuclidProp.
/* :Project FPGA-Imaging-Library :Design FrameController :Function For controlling a BlockRAM from xilinx. Give the first output after ram_read_latency cycles while the input enable. :Module Main module :Version 1.0 :Modified 2015-05-12 Copyright (C) 2015 Tianyu Dai (dtysky) <[email protected]> This library 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 library 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 library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Homepage for this project: http://fil.dtysky.moe Sources for this project: https://github.com/dtysky/FPGA-Imaging-Library My e-mail: [email protected] My blog: http://dtysky.moe */ `timescale 1ns / 1ps module FrameController( clk, rst_n, in_enable, in_data, out_ready, out_data, ram_addr); /* ::description This module's working mode. ::range 0 for Pipline, 1 for Req-ack */ parameter work_mode = 0; /* ::description This module's WR mode. ::range 0 for Write, 1 for Read */ parameter wr_mode = 0; /* ::description Data bit width. */ parameter data_width = 8; /* ::description Width of image. ::range 1 - 4096 */ parameter im_width = 320; /* ::description Height of image. ::range 1 - 4096 */ parameter im_height = 240; /* ::description Address bit width of a ram for storing this image. ::range Depend on im_width and im_height. */ parameter addr_width = 17; /* ::description RL of RAM, in xilinx 7-series device, it is 2. ::range 0 - 15, Depend on your using ram. */ parameter ram_read_latency = 2; /* ::description The first row you want to storing, used for eliminating offset. ::range Depend on your input offset. */ parameter row_init = 0; /* ::description Clock. */ input clk; /* ::description Reset, active low. */ input rst_n; /* ::description Input data enable, in pipeline mode, it works as another rst_n, in req-ack mode, only it is high will in_data can be really changes. */ input in_enable; /* ::description Input data, it must be synchronous with in_enable. */ input [data_width - 1 : 0] in_data; /* ::description Output data ready, in both two mode, it will be high while the out_data can be read. */ output out_ready; /* ::description Output data, it will be synchronous with out_ready. */ output[data_width - 1 : 0] out_data; /* ::description Address for ram. */ output[addr_width - 1 : 0] ram_addr; reg[addr_width - 1 : 0] reg_ram_addr; reg[3 : 0] con_ready; assign ram_addr = reg_ram_addr; assign out_data = out_ready ? in_data : 0; generate if(wr_mode == 0) begin if(work_mode == 0) begin always @(posedge clk or negedge rst_n or negedge in_enable) begin if(~rst_n || ~in_enable) reg_ram_addr <= row_init * im_width; else if(reg_ram_addr == im_width * im_height - 1) reg_ram_addr <= 0; else reg_ram_addr <= reg_ram_addr + 1; end end else begin always @(posedge in_enable or negedge rst_n) begin if(~rst_n) reg_ram_addr <= row_init * im_width - 1; else if(reg_ram_addr == im_width * im_height - 1) reg_ram_addr <= 0; else reg_ram_addr <= reg_ram_addr + 1; end end assign out_ready = ~rst_n || ~in_enable ? 0 : 1; end else begin if(work_mode == 0) begin always @(posedge clk or negedge rst_n or negedge in_enable) begin if(~rst_n || ~in_enable) reg_ram_addr <= 0; else if(reg_ram_addr == im_width * im_height - 1) reg_ram_addr <= 0; else reg_ram_addr <= reg_ram_addr + 1; end end else begin always @(posedge in_enable or negedge rst_n) begin if(~rst_n) reg_ram_addr <= 0 - 1; else if(reg_ram_addr == im_width * im_height - 1) reg_ram_addr <= 0; else reg_ram_addr <= reg_ram_addr + 1; end end always @(posedge clk or negedge rst_n or negedge in_enable) begin if(~rst_n || ~in_enable) con_ready <= 0; else if (con_ready == ram_read_latency) con_ready <= con_ready; else con_ready <= con_ready + 1; end assign out_ready = con_ready == ram_read_latency ? 1 : 0; end endgenerate endmodule
// ---------------------------------------------------------------------- // Copyright (c) 2016, The Regents of the University of California All // rights reserved. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are // met: // // * Redistributions of source code must retain the above copyright // notice, this list of conditions and the following disclaimer. // // * 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. // // * Neither the name of The Regents of the University of California // nor the names of its contributors may be used to endorse or // promote products derived from this software without specific // prior written permission. // // 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 REGENTS OF THE // UNIVERSITY OF CALIFORNIA 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. // ---------------------------------------------------------------------- //---------------------------------------------------------------------------- // Filename: rxr_engine_128.v // Version: 1.0 // Verilog Standard: Verilog-2001 // Description: The RXR Engine (Classic) takes a single stream of TLP // packets and provides the request packets on the RXR Interface. // This Engine is capable of operating at "line rate". // Author: Dustin Richmond (@darichmond) //----------------------------------------------------------------------------- `include "trellis.vh" `include "tlp.vh" module rxr_engine_128 #(parameter C_PCI_DATA_WIDTH = 128, parameter C_RX_PIPELINE_DEPTH=10) (// Interface: Clocks input CLK, // Interface: Resets input RST_BUS, // Replacement for generic RST_IN input RST_LOGIC, // Addition for RIFFA_RST output DONE_RXR_RST, // Interface: RX Classic input [C_PCI_DATA_WIDTH-1:0] RX_TLP, input RX_TLP_VALID, input RX_TLP_START_FLAG, input [`SIG_OFFSET_W-1:0] RX_TLP_START_OFFSET, input RX_TLP_END_FLAG, input [`SIG_OFFSET_W-1:0] RX_TLP_END_OFFSET, input [`SIG_BARDECODE_W-1:0] RX_TLP_BAR_DECODE, // Interface: RXR output [C_PCI_DATA_WIDTH-1:0] RXR_DATA, output RXR_DATA_VALID, output [(C_PCI_DATA_WIDTH/32)-1:0] RXR_DATA_WORD_ENABLE, output RXR_DATA_START_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] RXR_DATA_START_OFFSET, output RXR_DATA_END_FLAG, output [clog2s(C_PCI_DATA_WIDTH/32)-1:0] RXR_DATA_END_OFFSET, output [`SIG_FBE_W-1:0] RXR_META_FDWBE, output [`SIG_LBE_W-1:0] RXR_META_LDWBE, output [`SIG_TC_W-1:0] RXR_META_TC, output [`SIG_ATTR_W-1:0] RXR_META_ATTR, output [`SIG_TAG_W-1:0] RXR_META_TAG, output [`SIG_TYPE_W-1:0] RXR_META_TYPE, output [`SIG_ADDR_W-1:0] RXR_META_ADDR, output [`SIG_BARDECODE_W-1:0] RXR_META_BAR_DECODED, output [`SIG_REQID_W-1:0] RXR_META_REQUESTER_ID, output [`SIG_LEN_W-1:0] RXR_META_LENGTH, output RXR_META_EP, // Interface: RX Shift Register input [(C_RX_PIPELINE_DEPTH+1)*C_PCI_DATA_WIDTH-1:0] RX_SR_DATA, input [C_RX_PIPELINE_DEPTH:0] RX_SR_EOP, input [(C_RX_PIPELINE_DEPTH+1)*`SIG_OFFSET_W-1:0] RX_SR_END_OFFSET, input [(C_RX_PIPELINE_DEPTH+1)*`SIG_OFFSET_W-1:0] RX_SR_START_OFFSET, input [C_RX_PIPELINE_DEPTH:0] RX_SR_SOP, input [C_RX_PIPELINE_DEPTH:0] RX_SR_VALID ); /*AUTOWIRE*/ ///*AUTOOUTPUT*/ // End of automatics localparam C_RX_BE_W = (`SIG_FBE_W+`SIG_LBE_W); localparam C_RX_INPUT_STAGES = 1; localparam C_RX_OUTPUT_STAGES = 1; localparam C_RX_COMPUTATION_STAGES = 1; localparam C_RX_HDR_STAGES = 1; // Specific to the Xilinx 128-bit RXR Engine localparam C_TOTAL_STAGES = C_RX_COMPUTATION_STAGES + C_RX_OUTPUT_STAGES + C_RX_INPUT_STAGES + C_RX_HDR_STAGES; localparam C_OFFSET_WIDTH = clog2s(C_PCI_DATA_WIDTH/32); localparam C_STRADDLE_W = 64; localparam C_HDR_NOSTRADDLE_I = C_RX_INPUT_STAGES * C_PCI_DATA_WIDTH; localparam C_OUTPUT_STAGE_WIDTH = (C_PCI_DATA_WIDTH/32) + 2 + clog2s(C_PCI_DATA_WIDTH/32) + 1 + `SIG_FBE_W + `SIG_LBE_W + `SIG_TC_W + `SIG_ATTR_W + `SIG_TAG_W + `SIG_TYPE_W + `SIG_ADDR_W + `SIG_BARDECODE_W + `SIG_REQID_W + `SIG_LEN_W; // Header Reg Inputs wire [`SIG_OFFSET_W-1:0] __wRxrStartOffset; wire [`SIG_OFFSET_W-1:0] __wRxrStraddledStartOffset; wire [`TLP_MAXHDR_W-1:0] __wRxrHdr; wire [`TLP_MAXHDR_W-1:0] __wRxrHdrStraddled; wire [`TLP_MAXHDR_W-1:0] __wRxrHdrNotStraddled; wire __wRxrHdrValid; wire [`TLP_TYPE_W-1:0] __wRxrHdrType; wire [`TLP_TYPE_W-1:0] __wRxrHdrTypeStraddled; wire __wRxrHdrSOP; // Asserted on non-straddle SOP wire __wRxrHdrSOPStraddle; wire __wRxrHdr4DWHWDataSF; // Header Reg Outputs wire _wRxrHdrValid; wire [`TLP_MAXHDR_W-1:0] _wRxrHdr; wire [`SIG_ADDR_W-1:0] _wRxrAddrUnformatted; wire [`SIG_ADDR_W-1:0] _wRxrAddr; wire [63:0] _wRxrTlpMetadata; wire [`TLP_TYPE_W-1:0] _wRxrType; wire [`TLP_LEN_W-1:0] _wRxrLength; wire [2:0] _wRxrHdrHdrLen;// TODO: wire [`SIG_OFFSET_W-1:0] _wRxrHdrStartOffset;// TODO: wire _wRxrHdrDelayedSOP; wire _wRxrHdrSOPStraddle; wire _wRxrHdrSOP; wire _wRxrHdrSF; wire _wRxrHdrEF; wire _wRxrHdrSCP; // Single Cycle Packet wire _wRxrHdrMCP; // Multi Cycle Packet wire _wRxrHdrRegSF; wire _wRxrHdrRegValid; wire _wRxrHdr4DWHSF; wire _wRxrHdr4DWHNoDataSF; wire _wRxrHdr4DWHWDataSF; wire _wRxrHdr3DWHSF; wire [2:0] _wRxrHdrDataSoff; wire [1:0] _wRxrHdrDataEoff; wire [3:0] _wRxrHdrStartMask; wire [3:0] _wRxrHdrEndMask; // Header Reg Outputs wire wRxrHdrSF; wire wRxrHdrEF; wire wRxrHdrValid; wire [`TLP_MAXHDR_W-1:0] wRxrHdr; wire [63:0] wRxrMetadata; wire [`TLP_TYPE_W-1:0] wRxrType; wire [`TLP_LEN_W-1:0] wRxrLength; wire [2:0] wRxrHdrLength; // TODO: wire [`SIG_OFFSET_W-1:0] wRxrHdrStartOffset; // TODO: wire wRxrHdrSCP; // Single Cycle Packet wire wRxrHdrMCP; // Multi Cycle Packet wire [1:0] wRxrHdrDataSoff; wire [3:0] wRxrHdrStartMask; wire [3:0] wRxrHdrEndMask; // Output Register Inputs wire [C_PCI_DATA_WIDTH-1:0] wRxrData; wire wRxrDataValid; wire [(C_PCI_DATA_WIDTH/32)-1:0] wRxrDataWordEnable; wire wRxrDataStartFlag; wire [clog2s(C_PCI_DATA_WIDTH/32)-1:0] wRxrDataStartOffset; wire wRxrDataEndFlag; wire [clog2s(C_PCI_DATA_WIDTH/32)-1:0] wRxrDataEndOffset; wire [`SIG_FBE_W-1:0] wRxrMetaFdwbe; wire [`SIG_LBE_W-1:0] wRxrMetaLdwbe; wire [`SIG_TC_W-1:0] wRxrMetaTC; wire [`SIG_ATTR_W-1:0] wRxrMetaAttr; wire [`SIG_TAG_W-1:0] wRxrMetaTag; wire [`SIG_TYPE_W-1:0] wRxrMetaType; wire [`SIG_ADDR_W-1:0] wRxrMetaAddr; wire [`SIG_BARDECODE_W-1:0] wRxrMetaBarDecoded; wire [`SIG_REQID_W-1:0] wRxrMetaRequesterId; wire [`SIG_LEN_W-1:0] wRxrMetaLength; wire wRxrMetaEP; reg rStraddledSOP; reg rStraddledSOPSplit; reg rRST; assign DONE_RXR_RST = ~rRST; // ----- Header Register ----- assign __wRxrHdrSOP = RX_SR_SOP[C_RX_INPUT_STAGES] & ~__wRxrStartOffset[1]; assign __wRxrHdrSOPStraddle = RX_SR_SOP[C_RX_INPUT_STAGES] & __wRxrStraddledStartOffset[1]; assign __wRxrHdrNotStraddled = RX_SR_DATA[C_HDR_NOSTRADDLE_I +: C_PCI_DATA_WIDTH]; assign __wRxrHdrStraddled = {RX_SR_DATA[C_RX_INPUT_STAGES*C_PCI_DATA_WIDTH +: C_STRADDLE_W], RX_SR_DATA[(C_RX_INPUT_STAGES+1)*C_PCI_DATA_WIDTH + C_STRADDLE_W +: C_STRADDLE_W ]}; assign __wRxrStartOffset = RX_SR_START_OFFSET[`SIG_OFFSET_W*C_RX_INPUT_STAGES +: `SIG_OFFSET_W]; assign __wRxrStraddledStartOffset = RX_SR_START_OFFSET[`SIG_OFFSET_W*(C_RX_INPUT_STAGES) +: `SIG_OFFSET_W]; assign __wRxrHdrValid = __wRxrHdrSOP | ((rStraddledSOP | rStraddledSOPSplit) & RX_SR_VALID[C_RX_INPUT_STAGES]); assign __wRxrHdr4DWHWDataSF = (_wRxrHdr[`TLP_4DWHBIT_I] & _wRxrHdr[`TLP_PAYBIT_I] & RX_SR_VALID[C_RX_INPUT_STAGES] & _wRxrHdrDelayedSOP); assign _wRxrHdrHdrLen = {_wRxrHdr[`TLP_4DWHBIT_I],~_wRxrHdr[`TLP_4DWHBIT_I],~_wRxrHdr[`TLP_4DWHBIT_I]}; assign _wRxrHdrDataSoff = {1'b0,_wRxrHdrSOPStraddle,1'b0} + _wRxrHdrHdrLen; assign _wRxrHdrRegSF = RX_SR_SOP[C_RX_INPUT_STAGES + C_RX_HDR_STAGES]; assign _wRxrHdrRegValid = RX_SR_VALID[C_RX_INPUT_STAGES + C_RX_HDR_STAGES]; assign _wRxrHdr4DWHNoDataSF = _wRxrHdr[`TLP_4DWHBIT_I] & ~_wRxrHdr[`TLP_PAYBIT_I] & _wRxrHdrSOP; assign _wRxrHdr4DWHSF = _wRxrHdr4DWHNoDataSF | (_wRxrHdr4DWHWDataSF & _wRxrHdrRegValid); assign _wRxrHdr3DWHSF = ~_wRxrHdr[`TLP_4DWHBIT_I] & _wRxrHdrSOP; assign _wRxrHdrSF = (_wRxrHdr3DWHSF | _wRxrHdr4DWHSF | _wRxrHdrSOPStraddle); assign _wRxrHdrEF = RX_SR_EOP[C_RX_INPUT_STAGES + C_RX_HDR_STAGES]; assign _wRxrHdrDataEoff = RX_SR_END_OFFSET[(C_RX_INPUT_STAGES+C_RX_HDR_STAGES)*`SIG_OFFSET_W +: C_OFFSET_WIDTH]; assign _wRxrHdrSCP = _wRxrHdrSF & _wRxrHdrEF & (_wRxrHdr[`TLP_TYPE_R] == `TLP_TYPE_REQ); assign _wRxrHdrMCP = (_wRxrHdrSF & ~_wRxrHdrEF & (_wRxrHdr[`TLP_TYPE_R] == `TLP_TYPE_REQ)) | (wRxrHdrMCP & ~wRxrHdrEF); assign _wRxrHdrStartMask = {4{_wRxrHdr[`TLP_PAYBIT_I]}} << (_wRxrHdrSF ? _wRxrHdrDataSoff[1:0] : 0); assign wRxrDataWordEnable = wRxrHdrEndMask & wRxrHdrStartMask & {4{wRxrDataValid}}; assign wRxrDataValid = wRxrHdrSCP | wRxrHdrMCP; assign wRxrDataStartFlag = wRxrHdrSF; assign wRxrDataEndFlag = wRxrHdrEF; assign wRxrDataStartOffset = wRxrHdrDataSoff; assign wRxrMetaFdwbe = wRxrHdr[`TLP_REQFBE_R]; assign wRxrMetaLdwbe = wRxrHdr[`TLP_REQLBE_R]; assign wRxrMetaTC = wRxrHdr[`TLP_TC_R]; assign wRxrMetaAttr = {wRxrHdr[`TLP_ATTR1_R], wRxrHdr[`TLP_ATTR0_R]}; assign wRxrMetaTag = wRxrHdr[`TLP_REQTAG_R]; assign wRxrMetaAddr = wRxrHdr[`TLP_REQADDRDW0_I +: `TLP_REQADDR_W];/* TODO: REQADDR_R*/ assign wRxrMetaRequesterId = wRxrHdr[`TLP_REQREQID_R]; assign wRxrMetaLength = wRxrHdr[`TLP_LEN_R]; assign wRxrMetaEP = wRxrHdr[`TLP_EP_R]; assign wRxrMetaType = tlp_to_trellis_type({wRxrHdr[`TLP_FMT_R],wRxrHdr[`TLP_TYPE_R]}); assign RXR_DATA = RX_SR_DATA[C_PCI_DATA_WIDTH*C_TOTAL_STAGES +: C_PCI_DATA_WIDTH]; assign RXR_DATA_END_OFFSET = RX_SR_END_OFFSET[`SIG_OFFSET_W*(C_TOTAL_STAGES) +: C_OFFSET_WIDTH]; always @(posedge CLK) begin rStraddledSOP <= __wRxrHdrSOPStraddle; // Set Straddled SOP Split when there is a straddled packet where the // header is not contiguous. (Not sure if this is ever possible, but // better safe than sorry assert Straddled SOP Split. See Virtex 6 PCIe // errata. if(__wRxrHdrSOP | rRST) begin rStraddledSOPSplit <=0; end else begin rStraddledSOPSplit <= (__wRxrHdrSOPStraddle | rStraddledSOPSplit) & ~RX_SR_VALID[C_RX_INPUT_STAGES]; end end always @(posedge CLK) begin rRST <= RST_BUS | RST_LOGIC; end mux #( // Parameters .C_NUM_INPUTS (2), .C_CLOG_NUM_INPUTS (1), .C_WIDTH (`TLP_MAXHDR_W), .C_MUX_TYPE ("SELECT") /*AUTOINSTPARAM*/) hdr_mux ( // Outputs .MUX_OUTPUT (__wRxrHdr[`TLP_MAXHDR_W-1:0]), // Inputs .MUX_INPUTS ({__wRxrHdrStraddled[`TLP_MAXHDR_W-1:0], __wRxrHdrNotStraddled[`TLP_MAXHDR_W-1:0]}), .MUX_SELECT (rStraddledSOP | rStraddledSOPSplit) /*AUTOINST*/); register #( // Parameters .C_WIDTH (64 + 1), .C_VALUE (0) /*AUTOINSTPARAM*/) hdr_register_63_0 ( // Outputs .RD_DATA ({_wRxrHdr[C_STRADDLE_W-1:0], _wRxrHdrValid}), // Inputs .WR_DATA ({__wRxrHdr[C_STRADDLE_W-1:0], __wRxrHdrValid}), .WR_EN (__wRxrHdrSOP | rStraddledSOP), .RST_IN (0), /*AUTOINST*/ // Inputs .CLK (CLK)); register #( // Parameters .C_WIDTH (3), .C_VALUE (0) /*AUTOINSTPARAM*/) sf4dwh ( // Outputs .RD_DATA ({_wRxrHdr4DWHWDataSF, _wRxrHdrSOPStraddle,_wRxrHdrSOP}), // Inputs .WR_DATA ({__wRxrHdr4DWHWDataSF,rStraddledSOP,__wRxrHdrSOP}), .WR_EN (1), .RST_IN (0), /*AUTOINST*/ // Inputs .CLK (CLK)); register #( // Parameters .C_WIDTH (1), .C_VALUE (0) /*AUTOINSTPARAM*/) delayed_sop ( // Outputs .RD_DATA ({_wRxrHdrDelayedSOP}), // Inputs .WR_DATA ({__wRxrHdrSOP}), .WR_EN (RX_SR_VALID[C_RX_INPUT_STAGES]), .RST_IN (0), /*AUTOINST*/ // Inputs .CLK (CLK)); register #( // Parameters .C_WIDTH (64), .C_VALUE (0) /*AUTOINSTPARAM*/) hdr_register_127_64 ( // Outputs .RD_DATA (_wRxrHdr[`TLP_MAXHDR_W-1:C_STRADDLE_W]), // Inputs .WR_DATA (__wRxrHdr[`TLP_MAXHDR_W-1:C_STRADDLE_W]), .WR_EN (__wRxrHdrSOP | rStraddledSOP | rStraddledSOPSplit), // Non straddled start, Straddled, or straddled split .RST_IN (0), /*AUTOINST*/ // Inputs .CLK (CLK)); // ----- Computation Register ----- register #( // Parameters .C_WIDTH (64 + 4),/* TODO: TLP_METADATA_W*/ .C_VALUE (0) /*AUTOINSTPARAM*/) metadata (// Outputs .RD_DATA ({wRxrHdr[`TLP_REQMETADW0_I +: 64], wRxrHdrSF,wRxrHdrDataSoff, wRxrHdrEF}),/* TODO: TLP_METADATA_R and other signals*/ // Inputs .RST_IN (0), .WR_DATA ({_wRxrHdr[`TLP_REQMETADW0_I +: 64], _wRxrHdrSF,_wRxrHdrDataSoff[1:0], _wRxrHdrEF}),/* TODO: TLP_METADATA_R*/ .WR_EN (1), /*AUTOINST*/ // Inputs .CLK (CLK)); register #(// Parameters .C_WIDTH (3+8), .C_VALUE (0) /*AUTOINSTPARAM*/) metadata_valid (// Output .RD_DATA ({wRxrHdrValid, wRxrHdrSCP, wRxrHdrMCP, wRxrHdrEndMask, wRxrHdrStartMask}), // Inputs .RST_IN (0), .WR_DATA ({_wRxrHdrValid, _wRxrHdrSCP, _wRxrHdrMCP, _wRxrHdrEndMask, _wRxrHdrStartMask}), .WR_EN (1), /*AUTOINST*/ // Inputs .CLK (CLK)); register #(// Parameters .C_WIDTH (`SIG_ADDR_W/2), .C_VALUE (0) /*AUTOINSTPARAM*/) addr_63_32 (// Outputs .RD_DATA (wRxrHdr[`TLP_REQADDRHI_R]), // Inputs .RST_IN (~_wRxrHdr[`TLP_4DWHBIT_I]), .WR_DATA (_wRxrHdr[`TLP_REQADDRLO_R]), // Instead of a mux, we'll use the reset .WR_EN (1), /*AUTOINST*/ // Inputs .CLK (CLK)); register #(// Parameters .C_WIDTH (`SIG_ADDR_W/2), .C_VALUE (0) /*AUTOINSTPARAM*/) addr_31_0 (// Outputs .RD_DATA (wRxrHdr[`TLP_REQADDRLO_R]), // Inputs .RST_IN (0),// Never need to reset .WR_DATA (_wRxrHdr[`TLP_4DWHBIT_I] ? _wRxrHdr[`TLP_REQADDRHI_R] : _wRxrHdr[`TLP_REQADDRLO_R]), .WR_EN (1), /*AUTOINST*/ // Inputs .CLK (CLK)); offset_to_mask #(// Parameters .C_MASK_SWAP (0), .C_MASK_WIDTH (4) /*AUTOINSTPARAM*/) o2m_ef (// Outputs .MASK (_wRxrHdrEndMask), // Inputs .OFFSET_ENABLE (_wRxrHdrEF), .OFFSET (_wRxrHdrDataEoff) /*AUTOINST*/); pipeline #(// Parameters .C_DEPTH (C_RX_OUTPUT_STAGES), .C_WIDTH (C_OUTPUT_STAGE_WIDTH),// TODO: .C_USE_MEMORY (0) /*AUTOINSTPARAM*/) output_pipeline (// Outputs .WR_DATA_READY (), // Pinned to 1 .RD_DATA ({RXR_DATA_WORD_ENABLE, RXR_DATA_START_FLAG, RXR_DATA_START_OFFSET, RXR_DATA_END_FLAG, RXR_META_FDWBE, RXR_META_LDWBE, RXR_META_TC, RXR_META_ATTR, RXR_META_TAG, RXR_META_TYPE, RXR_META_ADDR, RXR_META_BAR_DECODED, RXR_META_REQUESTER_ID, RXR_META_LENGTH, RXR_META_EP}), .RD_DATA_VALID (RXR_DATA_VALID), // Inputs .WR_DATA ({wRxrDataWordEnable, wRxrDataStartFlag, wRxrDataStartOffset, wRxrDataEndFlag, wRxrMetaFdwbe, wRxrMetaLdwbe, wRxrMetaTC, wRxrMetaAttr, wRxrMetaTag, wRxrMetaType, wRxrMetaAddr, wRxrMetaBarDecoded, wRxrMetaRequesterId, wRxrMetaLength, wRxrMetaEP}), .WR_DATA_VALID (wRxrDataValid), .RD_DATA_READY (1'b1), .RST_IN (rRST), /*AUTOINST*/ // Inputs .CLK (CLK)); endmodule // Local Variables: // verilog-library-directories:("." "../../../common") // End:
(************************************************************************) (* v * The Coq Proof Assistant / The Coq Development Team *) (* <O___,, * INRIA - CNRS - LIX - LRI - PPS - Copyright 1999-2015 *) (* \VV/ **************************************************************) (* // * This file is distributed under the terms of the *) (* * GNU Lesser General Public License Version 2.1 *) (************************************************************************) Require Import ZAxioms ZMulOrder ZSgnAbs NZDiv. (** * Euclidean Division for integers (Trunc convention) We use here the convention known as Trunc, or Round-Toward-Zero, where [a/b] is the integer with the largest absolute value to be between zero and the exact fraction. It can be summarized by: [a = bq+r /\ 0 <= |r| < |b| /\ Sign(r) = Sign(a)] This is the convention of Ocaml and many other systems (C, ASM, ...). This convention is named "T" in the following paper: R. Boute, "The Euclidean definition of the functions div and mod", ACM Transactions on Programming Languages and Systems, Vol. 14, No.2, pp. 127-144, April 1992. See files [ZDivFloor] and [ZDivEucl] for others conventions. *) Module Type ZQuotProp (Import A : ZAxiomsSig') (Import B : ZMulOrderProp A) (Import C : ZSgnAbsProp A B). (** We benefit from what already exists for NZ *) Module Import Private_Div. Module Quot2Div <: NZDiv A. Definition div := quot. Definition modulo := A.rem. Definition div_wd := quot_wd. Definition mod_wd := rem_wd. Definition div_mod := quot_rem. Definition mod_bound_pos := rem_bound_pos. End Quot2Div. Module NZQuot := Nop <+ NZDivProp A Quot2Div B. End Private_Div. Ltac pos_or_neg a := let LT := fresh "LT" in let LE := fresh "LE" in destruct (le_gt_cases 0 a) as [LE|LT]; [|rewrite <- opp_pos_neg in LT]. (** Another formulation of the main equation *) Lemma rem_eq : forall a b, b~=0 -> a rem b == a - b*(a÷b). Proof. intros. rewrite <- add_move_l. symmetry. now apply quot_rem. Qed. (** A few sign rules (simple ones) *) Lemma rem_opp_opp : forall a b, b ~= 0 -> (-a) rem (-b) == - (a rem b). Proof. intros. now rewrite rem_opp_r, rem_opp_l. Qed. Lemma quot_opp_l : forall a b, b ~= 0 -> (-a)÷b == -(a÷b). Proof. intros. rewrite <- (mul_cancel_l _ _ b) by trivial. rewrite <- (add_cancel_r _ _ ((-a) rem b)). now rewrite <- quot_rem, rem_opp_l, mul_opp_r, <- opp_add_distr, <- quot_rem. Qed. Lemma quot_opp_r : forall a b, b ~= 0 -> a÷(-b) == -(a÷b). Proof. intros. assert (-b ~= 0) by (now rewrite eq_opp_l, opp_0). rewrite <- (mul_cancel_l _ _ (-b)) by trivial. rewrite <- (add_cancel_r _ _ (a rem (-b))). now rewrite <- quot_rem, rem_opp_r, mul_opp_opp, <- quot_rem. Qed. Lemma quot_opp_opp : forall a b, b ~= 0 -> (-a)÷(-b) == a÷b. Proof. intros. now rewrite quot_opp_r, quot_opp_l, opp_involutive. Qed. (** Uniqueness theorems *) Theorem quot_rem_unique : forall b q1 q2 r1 r2 : t, (0<=r1<b \/ b<r1<=0) -> (0<=r2<b \/ b<r2<=0) -> b*q1+r1 == b*q2+r2 -> q1 == q2 /\ r1 == r2. Proof. intros b q1 q2 r1 r2 Hr1 Hr2 EQ. destruct Hr1; destruct Hr2; try (intuition; order). apply NZQuot.div_mod_unique with b; trivial. rewrite <- (opp_inj_wd r1 r2). apply NZQuot.div_mod_unique with (-b); trivial. rewrite <- opp_lt_mono, opp_nonneg_nonpos; tauto. rewrite <- opp_lt_mono, opp_nonneg_nonpos; tauto. now rewrite 2 mul_opp_l, <- 2 opp_add_distr, opp_inj_wd. Qed. Theorem quot_unique: forall a b q r, 0<=a -> 0<=r<b -> a == b*q + r -> q == a÷b. Proof. intros; now apply NZQuot.div_unique with r. Qed. Theorem rem_unique: forall a b q r, 0<=a -> 0<=r<b -> a == b*q + r -> r == a rem b. Proof. intros; now apply NZQuot.mod_unique with q. Qed. (** A division by itself returns 1 *) Lemma quot_same : forall a, a~=0 -> a÷a == 1. Proof. intros. pos_or_neg a. apply NZQuot.div_same; order. rewrite <- quot_opp_opp by trivial. now apply NZQuot.div_same. Qed. Lemma rem_same : forall a, a~=0 -> a rem a == 0. Proof. intros. rewrite rem_eq, quot_same by trivial. nzsimpl. apply sub_diag. Qed. (** A division of a small number by a bigger one yields zero. *) Theorem quot_small: forall a b, 0<=a<b -> a÷b == 0. Proof. exact NZQuot.div_small. Qed. (** Same situation, in term of remulo: *) Theorem rem_small: forall a b, 0<=a<b -> a rem b == a. Proof. exact NZQuot.mod_small. Qed. (** * Basic values of divisions and modulo. *) Lemma quot_0_l: forall a, a~=0 -> 0÷a == 0. Proof. intros. pos_or_neg a. apply NZQuot.div_0_l; order. rewrite <- quot_opp_opp, opp_0 by trivial. now apply NZQuot.div_0_l. Qed. Lemma rem_0_l: forall a, a~=0 -> 0 rem a == 0. Proof. intros; rewrite rem_eq, quot_0_l; now nzsimpl. Qed. Lemma quot_1_r: forall a, a÷1 == a. Proof. intros. pos_or_neg a. now apply NZQuot.div_1_r. apply opp_inj. rewrite <- quot_opp_l. apply NZQuot.div_1_r; order. intro EQ; symmetry in EQ; revert EQ; apply lt_neq, lt_0_1. Qed. Lemma rem_1_r: forall a, a rem 1 == 0. Proof. intros. rewrite rem_eq, quot_1_r; nzsimpl; auto using sub_diag. intro EQ; symmetry in EQ; revert EQ; apply lt_neq; apply lt_0_1. Qed. Lemma quot_1_l: forall a, 1<a -> 1÷a == 0. Proof. exact NZQuot.div_1_l. Qed. Lemma rem_1_l: forall a, 1<a -> 1 rem a == 1. Proof. exact NZQuot.mod_1_l. Qed. Lemma quot_mul : forall a b, b~=0 -> (a*b)÷b == a. Proof. intros. pos_or_neg a; pos_or_neg b. apply NZQuot.div_mul; order. rewrite <- quot_opp_opp, <- mul_opp_r by order. apply NZQuot.div_mul; order. rewrite <- opp_inj_wd, <- quot_opp_l, <- mul_opp_l by order. apply NZQuot.div_mul; order. rewrite <- opp_inj_wd, <- quot_opp_r, <- mul_opp_opp by order. apply NZQuot.div_mul; order. Qed. Lemma rem_mul : forall a b, b~=0 -> (a*b) rem b == 0. Proof. intros. rewrite rem_eq, quot_mul by trivial. rewrite mul_comm; apply sub_diag. Qed. Theorem quot_unique_exact a b q: b~=0 -> a == b*q -> q == a÷b. Proof. intros Hb H. rewrite H, mul_comm. symmetry. now apply quot_mul. Qed. (** The sign of [a rem b] is the one of [a] (when it's not null) *) Lemma rem_nonneg : forall a b, b~=0 -> 0 <= a -> 0 <= a rem b. Proof. intros. pos_or_neg b. destruct (rem_bound_pos a b); order. rewrite <- rem_opp_r; trivial. destruct (rem_bound_pos a (-b)); trivial. Qed. Lemma rem_nonpos : forall a b, b~=0 -> a <= 0 -> a rem b <= 0. Proof. intros a b Hb Ha. apply opp_nonneg_nonpos. apply opp_nonneg_nonpos in Ha. rewrite <- rem_opp_l by trivial. now apply rem_nonneg. Qed. Lemma rem_sign_mul : forall a b, b~=0 -> 0 <= (a rem b) * a. Proof. intros a b Hb. destruct (le_ge_cases 0 a). apply mul_nonneg_nonneg; trivial. now apply rem_nonneg. apply mul_nonpos_nonpos; trivial. now apply rem_nonpos. Qed. Lemma rem_sign_nz : forall a b, b~=0 -> a rem b ~= 0 -> sgn (a rem b) == sgn a. Proof. intros a b Hb H. destruct (lt_trichotomy 0 a) as [LT|[EQ|LT]]. rewrite 2 sgn_pos; try easy. generalize (rem_nonneg a b Hb (lt_le_incl _ _ LT)). order. now rewrite <- EQ, rem_0_l, sgn_0. rewrite 2 sgn_neg; try easy. generalize (rem_nonpos a b Hb (lt_le_incl _ _ LT)). order. Qed. Lemma rem_sign : forall a b, a~=0 -> b~=0 -> sgn (a rem b) ~= -sgn a. Proof. intros a b Ha Hb H. destruct (eq_decidable (a rem b) 0) as [EQ|NEQ]. apply Ha, sgn_null_iff, opp_inj. now rewrite <- H, opp_0, EQ, sgn_0. apply Ha, sgn_null_iff. apply eq_mul_0_l with 2; try order'. nzsimpl'. apply add_move_0_l. rewrite <- H. symmetry. now apply rem_sign_nz. Qed. (** Operations and absolute value *) Lemma rem_abs_l : forall a b, b ~= 0 -> (abs a) rem b == abs (a rem b). Proof. intros a b Hb. destruct (le_ge_cases 0 a) as [LE|LE]. rewrite 2 abs_eq; try easy. now apply rem_nonneg. rewrite 2 abs_neq, rem_opp_l; try easy. now apply rem_nonpos. Qed. Lemma rem_abs_r : forall a b, b ~= 0 -> a rem (abs b) == a rem b. Proof. intros a b Hb. destruct (le_ge_cases 0 b). now rewrite abs_eq. now rewrite abs_neq, ?rem_opp_r. Qed. Lemma rem_abs : forall a b, b ~= 0 -> (abs a) rem (abs b) == abs (a rem b). Proof. intros. now rewrite rem_abs_r, rem_abs_l. Qed. Lemma quot_abs_l : forall a b, b ~= 0 -> (abs a)÷b == (sgn a)*(a÷b). Proof. intros a b Hb. destruct (lt_trichotomy 0 a) as [LT|[EQ|LT]]. rewrite abs_eq, sgn_pos by order. now nzsimpl. rewrite <- EQ, abs_0, quot_0_l; trivial. now nzsimpl. rewrite abs_neq, quot_opp_l, sgn_neg by order. rewrite mul_opp_l. now nzsimpl. Qed. Lemma quot_abs_r : forall a b, b ~= 0 -> a÷(abs b) == (sgn b)*(a÷b). Proof. intros a b Hb. destruct (lt_trichotomy 0 b) as [LT|[EQ|LT]]. rewrite abs_eq, sgn_pos by order. now nzsimpl. order. rewrite abs_neq, quot_opp_r, sgn_neg by order. rewrite mul_opp_l. now nzsimpl. Qed. Lemma quot_abs : forall a b, b ~= 0 -> (abs a)÷(abs b) == abs (a÷b). Proof. intros a b Hb. pos_or_neg a; [rewrite (abs_eq a)|rewrite (abs_neq a)]; try apply opp_nonneg_nonpos; try order. pos_or_neg b; [rewrite (abs_eq b)|rewrite (abs_neq b)]; try apply opp_nonneg_nonpos; try order. rewrite abs_eq; try easy. apply NZQuot.div_pos; order. rewrite <- abs_opp, <- quot_opp_r, abs_eq; try easy. apply NZQuot.div_pos; order. pos_or_neg b; [rewrite (abs_eq b)|rewrite (abs_neq b)]; try apply opp_nonneg_nonpos; try order. rewrite <- (abs_opp (_÷_)), <- quot_opp_l, abs_eq; try easy. apply NZQuot.div_pos; order. rewrite <- (quot_opp_opp a b), abs_eq; try easy. apply NZQuot.div_pos; order. Qed. (** We have a general bound for absolute values *) Lemma rem_bound_abs : forall a b, b~=0 -> abs (a rem b) < abs b. Proof. intros. rewrite <- rem_abs; trivial. apply rem_bound_pos. apply abs_nonneg. now apply abs_pos. Qed. (** * Order results about rem and quot *) (** A modulo cannot grow beyond its starting point. *) Theorem rem_le: forall a b, 0<=a -> 0<b -> a rem b <= a. Proof. exact NZQuot.mod_le. Qed. Theorem quot_pos : forall a b, 0<=a -> 0<b -> 0<= a÷b. Proof. exact NZQuot.div_pos. Qed. Lemma quot_str_pos : forall a b, 0<b<=a -> 0 < a÷b. Proof. exact NZQuot.div_str_pos. Qed. Lemma quot_small_iff : forall a b, b~=0 -> (a÷b==0 <-> abs a < abs b). Proof. intros. pos_or_neg a; pos_or_neg b. rewrite NZQuot.div_small_iff; try order. rewrite 2 abs_eq; intuition; order. rewrite <- opp_inj_wd, opp_0, <- quot_opp_r, NZQuot.div_small_iff by order. rewrite (abs_eq a), (abs_neq' b); intuition; order. rewrite <- opp_inj_wd, opp_0, <- quot_opp_l, NZQuot.div_small_iff by order. rewrite (abs_neq' a), (abs_eq b); intuition; order. rewrite <- quot_opp_opp, NZQuot.div_small_iff by order. rewrite (abs_neq' a), (abs_neq' b); intuition; order. Qed. Lemma rem_small_iff : forall a b, b~=0 -> (a rem b == a <-> abs a < abs b). Proof. intros. rewrite rem_eq, <- quot_small_iff by order. rewrite sub_move_r, <- (add_0_r a) at 1. rewrite add_cancel_l. rewrite eq_sym_iff, eq_mul_0. tauto. Qed. (** As soon as the divisor is strictly greater than 1, the division is strictly decreasing. *) Lemma quot_lt : forall a b, 0<a -> 1<b -> a÷b < a. Proof. exact NZQuot.div_lt. Qed. (** [le] is compatible with a positive division. *) Lemma quot_le_mono : forall a b c, 0<c -> a<=b -> a÷c <= b÷c. Proof. intros. pos_or_neg a. apply NZQuot.div_le_mono; auto. pos_or_neg b. apply le_trans with 0. rewrite <- opp_nonneg_nonpos, <- quot_opp_l by order. apply quot_pos; order. apply quot_pos; order. rewrite opp_le_mono in *. rewrite <- 2 quot_opp_l by order. apply NZQuot.div_le_mono; intuition; order. Qed. (** With this choice of division, rounding of quot is always done toward zero: *) Lemma mul_quot_le : forall a b, 0<=a -> b~=0 -> 0 <= b*(a÷b) <= a. Proof. intros. pos_or_neg b. split. apply mul_nonneg_nonneg; [|apply quot_pos]; order. apply NZQuot.mul_div_le; order. rewrite <- mul_opp_opp, <- quot_opp_r by order. split. apply mul_nonneg_nonneg; [|apply quot_pos]; order. apply NZQuot.mul_div_le; order. Qed. Lemma mul_quot_ge : forall a b, a<=0 -> b~=0 -> a <= b*(a÷b) <= 0. Proof. intros. rewrite <- opp_nonneg_nonpos, opp_le_mono, <-mul_opp_r, <-quot_opp_l by order. rewrite <- opp_nonneg_nonpos in *. destruct (mul_quot_le (-a) b); tauto. Qed. (** For positive numbers, considering [S (a÷b)] leads to an upper bound for [a] *) Lemma mul_succ_quot_gt: forall a b, 0<=a -> 0<b -> a < b*(S (a÷b)). Proof. exact NZQuot.mul_succ_div_gt. Qed. (** Similar results with negative numbers *) Lemma mul_pred_quot_lt: forall a b, a<=0 -> 0<b -> b*(P (a÷b)) < a. Proof. intros. rewrite opp_lt_mono, <- mul_opp_r, opp_pred, <- quot_opp_l by order. rewrite <- opp_nonneg_nonpos in *. now apply mul_succ_quot_gt. Qed. Lemma mul_pred_quot_gt: forall a b, 0<=a -> b<0 -> a < b*(P (a÷b)). Proof. intros. rewrite <- mul_opp_opp, opp_pred, <- quot_opp_r by order. rewrite <- opp_pos_neg in *. now apply mul_succ_quot_gt. Qed. Lemma mul_succ_quot_lt: forall a b, a<=0 -> b<0 -> b*(S (a÷b)) < a. Proof. intros. rewrite opp_lt_mono, <- mul_opp_l, <- quot_opp_opp by order. rewrite <- opp_nonneg_nonpos, <- opp_pos_neg in *. now apply mul_succ_quot_gt. Qed. (** Inequality [mul_quot_le] is exact iff the modulo is zero. *) Lemma quot_exact : forall a b, b~=0 -> (a == b*(a÷b) <-> a rem b == 0). Proof. intros. rewrite rem_eq by order. rewrite sub_move_r; nzsimpl; tauto. Qed. (** Some additionnal inequalities about quot. *) Theorem quot_lt_upper_bound: forall a b q, 0<=a -> 0<b -> a < b*q -> a÷b < q. Proof. exact NZQuot.div_lt_upper_bound. Qed. Theorem quot_le_upper_bound: forall a b q, 0<b -> a <= b*q -> a÷b <= q. Proof. intros. rewrite <- (quot_mul q b) by order. apply quot_le_mono; trivial. now rewrite mul_comm. Qed. Theorem quot_le_lower_bound: forall a b q, 0<b -> b*q <= a -> q <= a÷b. Proof. intros. rewrite <- (quot_mul q b) by order. apply quot_le_mono; trivial. now rewrite mul_comm. Qed. (** A division respects opposite monotonicity for the divisor *) Lemma quot_le_compat_l: forall p q r, 0<=p -> 0<q<=r -> p÷r <= p÷q. Proof. exact NZQuot.div_le_compat_l. Qed. (** * Relations between usual operations and rem and quot *) (** Unlike with other division conventions, some results here aren't always valid, and need to be restricted. For instance [(a+b*c) rem c <> a rem c] for [a=9,b=-5,c=2] *) Lemma rem_add : forall a b c, c~=0 -> 0 <= (a+b*c)*a -> (a + b * c) rem c == a rem c. Proof. assert (forall a b c, c~=0 -> 0<=a -> 0<=a+b*c -> (a+b*c) rem c == a rem c). intros. pos_or_neg c. apply NZQuot.mod_add; order. rewrite <- (rem_opp_r a), <- (rem_opp_r (a+b*c)) by order. rewrite <- mul_opp_opp in *. apply NZQuot.mod_add; order. intros a b c Hc Habc. destruct (le_0_mul _ _ Habc) as [(Habc',Ha)|(Habc',Ha)]. auto. apply opp_inj. revert Ha Habc'. rewrite <- 2 opp_nonneg_nonpos. rewrite <- 2 rem_opp_l, opp_add_distr, <- mul_opp_l by order. auto. Qed. Lemma quot_add : forall a b c, c~=0 -> 0 <= (a+b*c)*a -> (a + b * c) ÷ c == a ÷ c + b. Proof. intros. rewrite <- (mul_cancel_l _ _ c) by trivial. rewrite <- (add_cancel_r _ _ ((a+b*c) rem c)). rewrite <- quot_rem, rem_add by trivial. now rewrite mul_add_distr_l, add_shuffle0, <-quot_rem, mul_comm. Qed. Lemma quot_add_l: forall a b c, b~=0 -> 0 <= (a*b+c)*c -> (a * b + c) ÷ b == a + c ÷ b. Proof. intros a b c. rewrite add_comm, (add_comm a). now apply quot_add. Qed. (** Cancellations. *) Lemma quot_mul_cancel_r : forall a b c, b~=0 -> c~=0 -> (a*c)÷(b*c) == a÷b. Proof. assert (Aux1 : forall a b c, 0<=a -> 0<b -> c~=0 -> (a*c)÷(b*c) == a÷b). intros. pos_or_neg c. apply NZQuot.div_mul_cancel_r; order. rewrite <- quot_opp_opp, <- 2 mul_opp_r. apply NZQuot.div_mul_cancel_r; order. rewrite <- neq_mul_0; intuition order. assert (Aux2 : forall a b c, 0<=a -> b~=0 -> c~=0 -> (a*c)÷(b*c) == a÷b). intros. pos_or_neg b. apply Aux1; order. apply opp_inj. rewrite <- 2 quot_opp_r, <- mul_opp_l; try order. apply Aux1; order. rewrite <- neq_mul_0; intuition order. intros. pos_or_neg a. apply Aux2; order. apply opp_inj. rewrite <- 2 quot_opp_l, <- mul_opp_l; try order. apply Aux2; order. rewrite <- neq_mul_0; intuition order. Qed. Lemma quot_mul_cancel_l : forall a b c, b~=0 -> c~=0 -> (c*a)÷(c*b) == a÷b. Proof. intros. rewrite !(mul_comm c); now apply quot_mul_cancel_r. Qed. Lemma mul_rem_distr_r: forall a b c, b~=0 -> c~=0 -> (a*c) rem (b*c) == (a rem b) * c. Proof. intros. assert (b*c ~= 0) by (rewrite <- neq_mul_0; tauto). rewrite ! rem_eq by trivial. rewrite quot_mul_cancel_r by order. now rewrite mul_sub_distr_r, <- !mul_assoc, (mul_comm (a÷b) c). Qed. Lemma mul_rem_distr_l: forall a b c, b~=0 -> c~=0 -> (c*a) rem (c*b) == c * (a rem b). Proof. intros; rewrite !(mul_comm c); now apply mul_rem_distr_r. Qed. (** Operations modulo. *) Theorem rem_rem: forall a n, n~=0 -> (a rem n) rem n == a rem n. Proof. intros. pos_or_neg a; pos_or_neg n. apply NZQuot.mod_mod; order. rewrite <- ! (rem_opp_r _ n) by trivial. apply NZQuot.mod_mod; order. apply opp_inj. rewrite <- !rem_opp_l by order. apply NZQuot.mod_mod; order. apply opp_inj. rewrite <- !rem_opp_opp by order. apply NZQuot.mod_mod; order. Qed. Lemma mul_rem_idemp_l : forall a b n, n~=0 -> ((a rem n)*b) rem n == (a*b) rem n. Proof. assert (Aux1 : forall a b n, 0<=a -> 0<=b -> n~=0 -> ((a rem n)*b) rem n == (a*b) rem n). intros. pos_or_neg n. apply NZQuot.mul_mod_idemp_l; order. rewrite <- ! (rem_opp_r _ n) by order. apply NZQuot.mul_mod_idemp_l; order. assert (Aux2 : forall a b n, 0<=a -> n~=0 -> ((a rem n)*b) rem n == (a*b) rem n). intros. pos_or_neg b. now apply Aux1. apply opp_inj. rewrite <-2 rem_opp_l, <-2 mul_opp_r by order. apply Aux1; order. intros a b n Hn. pos_or_neg a. now apply Aux2. apply opp_inj. rewrite <-2 rem_opp_l, <-2 mul_opp_l, <-rem_opp_l by order. apply Aux2; order. Qed. Lemma mul_rem_idemp_r : forall a b n, n~=0 -> (a*(b rem n)) rem n == (a*b) rem n. Proof. intros. rewrite !(mul_comm a). now apply mul_rem_idemp_l. Qed. Theorem mul_rem: forall a b n, n~=0 -> (a * b) rem n == ((a rem n) * (b rem n)) rem n. Proof. intros. now rewrite mul_rem_idemp_l, mul_rem_idemp_r. Qed. (** addition and modulo Generally speaking, unlike with other conventions, we don't have [(a+b) rem n = (a rem n + b rem n) rem n] for any a and b. For instance, take (8 + (-10)) rem 3 = -2 whereas (8 rem 3 + (-10 rem 3)) rem 3 = 1. *) Lemma add_rem_idemp_l : forall a b n, n~=0 -> 0 <= a*b -> ((a rem n)+b) rem n == (a+b) rem n. Proof. assert (Aux : forall a b n, 0<=a -> 0<=b -> n~=0 -> ((a rem n)+b) rem n == (a+b) rem n). intros. pos_or_neg n. apply NZQuot.add_mod_idemp_l; order. rewrite <- ! (rem_opp_r _ n) by order. apply NZQuot.add_mod_idemp_l; order. intros a b n Hn Hab. destruct (le_0_mul _ _ Hab) as [(Ha,Hb)|(Ha,Hb)]. now apply Aux. apply opp_inj. rewrite <-2 rem_opp_l, 2 opp_add_distr, <-rem_opp_l by order. rewrite <- opp_nonneg_nonpos in *. now apply Aux. Qed. Lemma add_rem_idemp_r : forall a b n, n~=0 -> 0 <= a*b -> (a+(b rem n)) rem n == (a+b) rem n. Proof. intros. rewrite !(add_comm a). apply add_rem_idemp_l; trivial. now rewrite mul_comm. Qed. Theorem add_rem: forall a b n, n~=0 -> 0 <= a*b -> (a+b) rem n == (a rem n + b rem n) rem n. Proof. intros a b n Hn Hab. rewrite add_rem_idemp_l, add_rem_idemp_r; trivial. reflexivity. destruct (le_0_mul _ _ Hab) as [(Ha,Hb)|(Ha,Hb)]; destruct (le_0_mul _ _ (rem_sign_mul b n Hn)) as [(Hb',Hm)|(Hb',Hm)]; auto using mul_nonneg_nonneg, mul_nonpos_nonpos. setoid_replace b with 0 by order. rewrite rem_0_l by order. nzsimpl; order. setoid_replace b with 0 by order. rewrite rem_0_l by order. nzsimpl; order. Qed. (** Conversely, the following results need less restrictions here. *) Lemma quot_quot : forall a b c, b~=0 -> c~=0 -> (a÷b)÷c == a÷(b*c). Proof. assert (Aux1 : forall a b c, 0<=a -> 0<b -> c~=0 -> (a÷b)÷c == a÷(b*c)). intros. pos_or_neg c. apply NZQuot.div_div; order. apply opp_inj. rewrite <- 2 quot_opp_r, <- mul_opp_r; trivial. apply NZQuot.div_div; order. rewrite <- neq_mul_0; intuition order. assert (Aux2 : forall a b c, 0<=a -> b~=0 -> c~=0 -> (a÷b)÷c == a÷(b*c)). intros. pos_or_neg b. apply Aux1; order. apply opp_inj. rewrite <- quot_opp_l, <- 2 quot_opp_r, <- mul_opp_l; trivial. apply Aux1; trivial. rewrite <- neq_mul_0; intuition order. intros. pos_or_neg a. apply Aux2; order. apply opp_inj. rewrite <- 3 quot_opp_l; try order. apply Aux2; order. rewrite <- neq_mul_0. tauto. Qed. Lemma mod_mul_r : forall a b c, b~=0 -> c~=0 -> a rem (b*c) == a rem b + b*((a÷b) rem c). Proof. intros a b c Hb Hc. apply add_cancel_l with (b*c*(a÷(b*c))). rewrite <- quot_rem by (apply neq_mul_0; split; order). rewrite <- quot_quot by trivial. rewrite add_assoc, add_shuffle0, <- mul_assoc, <- mul_add_distr_l. rewrite <- quot_rem by order. apply quot_rem; order. Qed. (** A last inequality: *) Theorem quot_mul_le: forall a b c, 0<=a -> 0<b -> 0<=c -> c*(a÷b) <= (c*a)÷b. Proof. exact NZQuot.div_mul_le. Qed. End ZQuotProp.
(** Extraction : tests of optimizations of pattern matching *) Require Coq.extraction.Extraction. (** First, a few basic tests *) Definition test1 b := match b with | true => true | false => false end. Extraction test1. (** should be seen as the identity *) Definition test2 b := match b with | true => false | false => false end. Extraction test2. (** should be seen a the always-false constant function *) Inductive hole (A:Set) : Set := Hole | Hole2. Definition wrong_id (A B : Set) (x:hole A) : hole B := match x with | Hole _ => @Hole _ | Hole2 _ => @Hole2 _ end. Extraction wrong_id. (** should _not_ be optimized as an identity *) Definition test3 (A:Type)(o : option A) := match o with | Some x => Some x | None => None end. Extraction test3. (** Even with type parameters, should be seen as identity *) Inductive indu : Type := A : nat -> indu | B | C. Definition test4 n := match n with | A m => A (S m) | B => B | C => C end. Extraction test4. (** should merge branchs B C into a x->x *) Definition test5 n := match n with | A m => A (S m) | B => B | C => B end. Extraction test5. (** should merge branches B C into _->B *) Inductive indu' : Type := A' : nat -> indu' | B' | C' | D' | E' | F'. Definition test6 n := match n with | A' m => A' (S m) | B' => C' | C' => C' | D' => C' | E' => B' | F' => B' end. Extraction test6. (** should merge some branches into a _->C' *) (** NB : In Coq, "| a => a" corresponds to n, hence some "| _ -> n" are extracted *) Definition test7 n := match n with | A m => Some m | B => None | C => None end. Extraction test7. (** should merge branches B,C into a _->None *) (** Script from bug #2413 *) Set Implicit Arguments. Section S. Definition message := nat. Definition word := nat. Definition mode := nat. Definition opcode := nat. Variable condition : word -> option opcode. Section decoder_result. Variable inst : Type. Inductive decoder_result : Type := | DecUndefined : decoder_result | DecUnpredictable : decoder_result | DecInst : inst -> decoder_result | DecError : message -> decoder_result. End decoder_result. Definition decode_cond_mode (mode : Type) (f : word -> decoder_result mode) (w : word) (inst : Type) (g : mode -> opcode -> inst) : decoder_result inst := match condition w with | Some oc => match f w with | DecInst i => DecInst (g i oc) | DecError _ m => @DecError inst m | DecUndefined _ => @DecUndefined inst | DecUnpredictable _ => @DecUnpredictable inst end | None => @DecUndefined inst end. End S. Extraction decode_cond_mode. (** inner match should not be factorized with a partial x->x (different type) *)