/*
 * Copyright (c) 2020, Technische Universität Kaiserslautern
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 * 1. Redistributions of source code must retain the above copyright notice,
 *    this list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * 3. Neither the name of the copyright holder 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 THE COPYRIGHT HOLDER
 * 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.
 *
 * Authors:
 *    Lukas Steiner
 *    Derek Christ
 */

#ifndef MEMSPECDDR5_H
#define MEMSPECDDR5_H

#include <systemc>
#include <DRAMSys/configuration/memspec/MemSpec.h>

class MemSpecDDR5 final : public MemSpec
{
public:
    explicit MemSpecDDR5(const DRAMSys::Config::MemSpec &memSpec);

    const unsigned dimmRanksPerChannel;
    const unsigned physicalRanksPerDimmRank;
    const unsigned physicalRanksPerChannel;
    const unsigned logicalRanksPerPhysicalRank;
    const unsigned logicalRanksPerChannel;
    const unsigned cmdMode;
    const unsigned refMode;
    const unsigned RAAIMT;
    const unsigned RAAMMT;
    const unsigned RAACDR;

    // Memspec Variables:
    const sc_core::sc_time tRCD;
    const sc_core::sc_time tPPD;
    const sc_core::sc_time tRP;
    const sc_core::sc_time tRAS;
    const sc_core::sc_time tRC;
    const sc_core::sc_time tRL;
    const sc_core::sc_time tRTP;
    const sc_core::sc_time tRPRE;
    const sc_core::sc_time tRPST;
    const sc_core::sc_time tRDDQS;
    const sc_core::sc_time tWL;
    const sc_core::sc_time tWPRE;
    const sc_core::sc_time tWPST;
    const sc_core::sc_time tWR;
    const sc_core::sc_time tCCD_L_slr;
    const sc_core::sc_time tCCD_L_WR_slr;
    const sc_core::sc_time tCCD_L_WR2_slr;
    const sc_core::sc_time tCCD_S_slr;
    const sc_core::sc_time tCCD_S_WR_slr;
    const sc_core::sc_time tCCD_dlr;
    const sc_core::sc_time tCCD_WR_dlr;
    const sc_core::sc_time tCCD_WR_dpr;
    const sc_core::sc_time tRRD_L_slr;
    const sc_core::sc_time tRRD_S_slr;
    const sc_core::sc_time tRRD_dlr;
    const sc_core::sc_time tFAW_slr;
    const sc_core::sc_time tFAW_dlr;
    const sc_core::sc_time tWTR_L;
    const sc_core::sc_time tWTR_S;
    const sc_core::sc_time tRFC_slr;
    const sc_core::sc_time tRFC_dlr;
    const sc_core::sc_time tRFC_dpr;
    const sc_core::sc_time tRFCsb_slr;
    const sc_core::sc_time tRFCsb_dlr;
    const sc_core::sc_time tREFI;
    const sc_core::sc_time tREFIsb;
    const sc_core::sc_time tREFSBRD_slr;
    const sc_core::sc_time tREFSBRD_dlr;
    const sc_core::sc_time tRTRS;

    const sc_core::sc_time tCPDED;
    const sc_core::sc_time tPD;
    const sc_core::sc_time tXP;
    const sc_core::sc_time tACTPDEN;
    const sc_core::sc_time tPRPDEN;
    const sc_core::sc_time tREFPDEN;

    const sc_core::sc_time shortCmdOffset;
    const sc_core::sc_time longCmdOffset;

    const sc_core::sc_time tBURST16;
    const sc_core::sc_time tBURST32;

    // Currents and Voltages:
    // TODO: to be completed

    sc_core::sc_time getRefreshIntervalAB() const override;
    sc_core::sc_time getRefreshIntervalSB() const override;

    unsigned getRAACDR() const override;
    unsigned getRAAIMT() const override;
    unsigned getRAAMMT() const override;

    sc_core::sc_time getExecutionTime(Command command, const tlm::tlm_generic_payload &payload) const override;
    TimeInterval getIntervalOnDataStrobe(Command command, const tlm::tlm_generic_payload &payload) const override;
};

#endif // MEMSPECDDR5_H
