/*
 * Copyright (c) 2021, 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
 */

#ifndef MEMSPECLPDDR5_H
#define MEMSPECLPDDR5_H

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

#include <nlohmann/json.hpp>

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

    // Memspec Variables:
    const sc_core::sc_time tREFI;
    const sc_core::sc_time tREFIpb;
    const sc_core::sc_time tRFCab;
    const sc_core::sc_time tRFCpb;
    const sc_core::sc_time tRAS;
    const sc_core::sc_time tRPab;
    const sc_core::sc_time tRPpb;
    const sc_core::sc_time tRCpb;
    const sc_core::sc_time tRCab;
    const sc_core::sc_time tPPD;
    const sc_core::sc_time tRCD;
    const sc_core::sc_time tFAW;
    const sc_core::sc_time tRRD;
    //const sc_core::sc_time tCCD;
    const sc_core::sc_time tRL;
    //const sc_core::sc_time tRPST;
    //const sc_core::sc_time tDQSCK;
    const sc_core::sc_time tRBTP;
    const sc_core::sc_time tWL;
    //const sc_core::sc_time tDQSS;
    //const sc_core::sc_time tDQS2DQ;
    const sc_core::sc_time tWR;
    //const sc_core::sc_time tWPRE;
    //const sc_core::sc_time tWTR;
    //const sc_core::sc_time tXP;
    //const sc_core::sc_time tSR;
    //const sc_core::sc_time tXSR;
    //const sc_core::sc_time tESCKE;
    //const sc_core::sc_time tCKE;
    //const sc_core::sc_time tCMDCKE;
    const sc_core::sc_time tRTRS;

    const sc_core::sc_time BL_n_min_16;
    const sc_core::sc_time BL_n_max_16;
    const sc_core::sc_time BL_n_L_16;
    const sc_core::sc_time BL_n_S_16;

    const sc_core::sc_time BL_n_min_32;
    const sc_core::sc_time BL_n_max_32;
    const sc_core::sc_time BL_n_L_32;
    const sc_core::sc_time BL_n_S_32;

    const sc_core::sc_time tWTR_L;
    const sc_core::sc_time tWTR_S;
    const sc_core::sc_time tWCK2DQO;

    const sc_core::sc_time tpbR2act;
    const sc_core::sc_time tpbR2pbR;

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

    const enum class BankMode {M16B, MBG, M8B} bankMode;

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

    sc_core::sc_time getRefreshIntervalAB() const override;
    sc_core::sc_time getRefreshIntervalPB() const override;
    sc_core::sc_time getRefreshIntervalP2B() const override;

    unsigned getPer2BankOffset() 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;

private:
    unsigned per2BankOffset;
};

#endif // MEMSPECLPDDR5_H
