// ==============================================================
// RTL generated by Vivado(TM) HLS - High-Level Synthesis from C, C++ and SystemC
// Version: 2016.2
// Copyright (C) 1986-2016 Xilinx, Inc. All Rights Reserved.
// 
// ===========================================================

#include "lcddrv_read_mem.h"
#include "AESL_pkg.h"

using namespace std;

namespace ap_rtl {

const sc_logic lcddrv_read_mem::ap_const_logic_1 = sc_dt::Log_1;
const sc_logic lcddrv_read_mem::ap_const_logic_0 = sc_dt::Log_0;
const sc_lv<6> lcddrv_read_mem::ap_ST_st1_fsm_0 = "1";
const sc_lv<6> lcddrv_read_mem::ap_ST_st2_fsm_1 = "10";
const sc_lv<6> lcddrv_read_mem::ap_ST_st3_fsm_2 = "100";
const sc_lv<6> lcddrv_read_mem::ap_ST_st4_fsm_3 = "1000";
const sc_lv<6> lcddrv_read_mem::ap_ST_st5_fsm_4 = "10000";
const sc_lv<6> lcddrv_read_mem::ap_ST_st6_fsm_5 = "100000";
const sc_lv<32> lcddrv_read_mem::ap_const_lv32_0 = "00000000000000000000000000000000";
const sc_lv<1> lcddrv_read_mem::ap_const_lv1_1 = "1";
const sc_lv<32> lcddrv_read_mem::ap_const_lv32_3 = "11";
const sc_lv<32> lcddrv_read_mem::ap_const_lv32_1 = "1";
const sc_lv<1> lcddrv_read_mem::ap_const_lv1_0 = "0";
const sc_lv<32> lcddrv_read_mem::ap_const_lv32_4 = "100";
const sc_lv<32> lcddrv_read_mem::ap_const_lv32_5 = "101";

lcddrv_read_mem::lcddrv_read_mem(sc_module_name name) : sc_module(name), mVcdFile(0) {

    SC_METHOD(thread_ap_clk_no_reset_);
    dont_initialize();
    sensitive << ( ap_clk.pos() );

    SC_METHOD(thread_ap_done);
    sensitive << ( ap_start );
    sensitive << ( ap_sig_cseq_ST_st1_fsm_0 );
    sensitive << ( ap_sig_cseq_ST_st6_fsm_5 );

    SC_METHOD(thread_ap_idle);
    sensitive << ( ap_start );
    sensitive << ( ap_sig_cseq_ST_st1_fsm_0 );

    SC_METHOD(thread_ap_ready);
    sensitive << ( ap_sig_cseq_ST_st6_fsm_5 );

    SC_METHOD(thread_ap_return);
    sensitive << ( dt_reg_67 );
    sensitive << ( ap_sig_cseq_ST_st6_fsm_5 );

    SC_METHOD(thread_ap_sig_23);
    sensitive << ( ap_CS_fsm );

    SC_METHOD(thread_ap_sig_48);
    sensitive << ( ap_CS_fsm );

    SC_METHOD(thread_ap_sig_55);
    sensitive << ( ap_CS_fsm );

    SC_METHOD(thread_ap_sig_64);
    sensitive << ( ap_CS_fsm );

    SC_METHOD(thread_ap_sig_73);
    sensitive << ( ap_CS_fsm );

    SC_METHOD(thread_ap_sig_cseq_ST_st1_fsm_0);
    sensitive << ( ap_sig_23 );

    SC_METHOD(thread_ap_sig_cseq_ST_st2_fsm_1);
    sensitive << ( ap_sig_55 );

    SC_METHOD(thread_ap_sig_cseq_ST_st4_fsm_3);
    sensitive << ( ap_sig_48 );

    SC_METHOD(thread_ap_sig_cseq_ST_st5_fsm_4);
    sensitive << ( ap_sig_64 );

    SC_METHOD(thread_ap_sig_cseq_ST_st6_fsm_5);
    sensitive << ( ap_sig_73 );

    SC_METHOD(thread_mem_ack_read_read_fu_55_p2);
    sensitive << ( mem_ack );
    sensitive << ( ap_sig_cseq_ST_st4_fsm_3 );

    SC_METHOD(thread_mem_addr);
    sensitive << ( addr );
    sensitive << ( ap_sig_cseq_ST_st4_fsm_3 );
    sensitive << ( ap_sig_cseq_ST_st2_fsm_1 );

    SC_METHOD(thread_mem_addr_ap_vld);
    sensitive << ( ap_sig_cseq_ST_st4_fsm_3 );
    sensitive << ( ap_sig_cseq_ST_st2_fsm_1 );

    SC_METHOD(thread_mem_req);
    sensitive << ( ap_sig_cseq_ST_st4_fsm_3 );
    sensitive << ( ap_sig_cseq_ST_st2_fsm_1 );
    sensitive << ( ap_sig_cseq_ST_st5_fsm_4 );

    SC_METHOD(thread_mem_req_ap_vld);
    sensitive << ( ap_sig_cseq_ST_st4_fsm_3 );
    sensitive << ( ap_sig_cseq_ST_st2_fsm_1 );
    sensitive << ( ap_sig_cseq_ST_st5_fsm_4 );

    SC_METHOD(thread_ap_NS_fsm);
    sensitive << ( ap_start );
    sensitive << ( ap_CS_fsm );
    sensitive << ( mem_ack_read_read_fu_55_p2 );

    ap_CS_fsm = "000001";
    static int apTFileNum = 0;
    stringstream apTFilenSS;
    apTFilenSS << "lcddrv_read_mem_sc_trace_" << apTFileNum ++;
    string apTFn = apTFilenSS.str();
    mVcdFile = sc_create_vcd_trace_file(apTFn.c_str());
    mVcdFile->set_time_unit(1, SC_PS);
    if (1) {
#ifdef __HLS_TRACE_LEVEL_PORT_HIER__
    sc_trace(mVcdFile, ap_clk, "(port)ap_clk");
    sc_trace(mVcdFile, ap_rst, "(port)ap_rst");
    sc_trace(mVcdFile, ap_start, "(port)ap_start");
    sc_trace(mVcdFile, ap_done, "(port)ap_done");
    sc_trace(mVcdFile, ap_idle, "(port)ap_idle");
    sc_trace(mVcdFile, ap_ready, "(port)ap_ready");
    sc_trace(mVcdFile, addr, "(port)addr");
    sc_trace(mVcdFile, mem_addr, "(port)mem_addr");
    sc_trace(mVcdFile, mem_addr_ap_vld, "(port)mem_addr_ap_vld");
    sc_trace(mVcdFile, mem_req, "(port)mem_req");
    sc_trace(mVcdFile, mem_req_ap_vld, "(port)mem_req_ap_vld");
    sc_trace(mVcdFile, mem_din, "(port)mem_din");
    sc_trace(mVcdFile, mem_ack, "(port)mem_ack");
    sc_trace(mVcdFile, ap_return, "(port)ap_return");
#endif
#ifdef __HLS_TRACE_LEVEL_INT__
    sc_trace(mVcdFile, ap_CS_fsm, "ap_CS_fsm");
    sc_trace(mVcdFile, ap_sig_cseq_ST_st1_fsm_0, "ap_sig_cseq_ST_st1_fsm_0");
    sc_trace(mVcdFile, ap_sig_23, "ap_sig_23");
    sc_trace(mVcdFile, dt_reg_67, "dt_reg_67");
    sc_trace(mVcdFile, ap_sig_cseq_ST_st4_fsm_3, "ap_sig_cseq_ST_st4_fsm_3");
    sc_trace(mVcdFile, ap_sig_48, "ap_sig_48");
    sc_trace(mVcdFile, ap_sig_cseq_ST_st2_fsm_1, "ap_sig_cseq_ST_st2_fsm_1");
    sc_trace(mVcdFile, ap_sig_55, "ap_sig_55");
    sc_trace(mVcdFile, ap_sig_cseq_ST_st5_fsm_4, "ap_sig_cseq_ST_st5_fsm_4");
    sc_trace(mVcdFile, ap_sig_64, "ap_sig_64");
    sc_trace(mVcdFile, mem_ack_read_read_fu_55_p2, "mem_ack_read_read_fu_55_p2");
    sc_trace(mVcdFile, ap_sig_cseq_ST_st6_fsm_5, "ap_sig_cseq_ST_st6_fsm_5");
    sc_trace(mVcdFile, ap_sig_73, "ap_sig_73");
    sc_trace(mVcdFile, ap_NS_fsm, "ap_NS_fsm");
#endif

    }
}

lcddrv_read_mem::~lcddrv_read_mem() {
    if (mVcdFile) 
        sc_close_vcd_trace_file(mVcdFile);

}

void lcddrv_read_mem::thread_ap_clk_no_reset_() {
    if ( ap_rst.read() == ap_const_logic_1) {
        ap_CS_fsm = ap_ST_st1_fsm_0;
    } else {
        ap_CS_fsm = ap_NS_fsm.read();
    }
    if (esl_seteq<1,1,1>(ap_const_logic_1, ap_sig_cseq_ST_st4_fsm_3.read())) {
        dt_reg_67 = mem_din.read();
    }
}

void lcddrv_read_mem::thread_ap_done() {
    if (((esl_seteq<1,1,1>(ap_const_logic_0, ap_start.read()) && 
          esl_seteq<1,1,1>(ap_const_logic_1, ap_sig_cseq_ST_st1_fsm_0.read())) || 
         esl_seteq<1,1,1>(ap_const_logic_1, ap_sig_cseq_ST_st6_fsm_5.read()))) {
        ap_done = ap_const_logic_1;
    } else {
        ap_done = ap_const_logic_0;
    }
}

void lcddrv_read_mem::thread_ap_idle() {
    if ((esl_seteq<1,1,1>(ap_const_logic_0, ap_start.read()) && 
         esl_seteq<1,1,1>(ap_const_logic_1, ap_sig_cseq_ST_st1_fsm_0.read()))) {
        ap_idle = ap_const_logic_1;
    } else {
        ap_idle = ap_const_logic_0;
    }
}

void lcddrv_read_mem::thread_ap_ready() {
    if (esl_seteq<1,1,1>(ap_const_logic_1, ap_sig_cseq_ST_st6_fsm_5.read())) {
        ap_ready = ap_const_logic_1;
    } else {
        ap_ready = ap_const_logic_0;
    }
}

void lcddrv_read_mem::thread_ap_return() {
    ap_return = dt_reg_67.read();
}

void lcddrv_read_mem::thread_ap_sig_23() {
    ap_sig_23 = esl_seteq<1,1,1>(ap_CS_fsm.read().range(0, 0), ap_const_lv1_1);
}

void lcddrv_read_mem::thread_ap_sig_48() {
    ap_sig_48 = esl_seteq<1,1,1>(ap_const_lv1_1, ap_CS_fsm.read().range(3, 3));
}

void lcddrv_read_mem::thread_ap_sig_55() {
    ap_sig_55 = esl_seteq<1,1,1>(ap_const_lv1_1, ap_CS_fsm.read().range(1, 1));
}

void lcddrv_read_mem::thread_ap_sig_64() {
    ap_sig_64 = esl_seteq<1,1,1>(ap_const_lv1_1, ap_CS_fsm.read().range(4, 4));
}

void lcddrv_read_mem::thread_ap_sig_73() {
    ap_sig_73 = esl_seteq<1,1,1>(ap_const_lv1_1, ap_CS_fsm.read().range(5, 5));
}

void lcddrv_read_mem::thread_ap_sig_cseq_ST_st1_fsm_0() {
    if (ap_sig_23.read()) {
        ap_sig_cseq_ST_st1_fsm_0 = ap_const_logic_1;
    } else {
        ap_sig_cseq_ST_st1_fsm_0 = ap_const_logic_0;
    }
}

void lcddrv_read_mem::thread_ap_sig_cseq_ST_st2_fsm_1() {
    if (ap_sig_55.read()) {
        ap_sig_cseq_ST_st2_fsm_1 = ap_const_logic_1;
    } else {
        ap_sig_cseq_ST_st2_fsm_1 = ap_const_logic_0;
    }
}

void lcddrv_read_mem::thread_ap_sig_cseq_ST_st4_fsm_3() {
    if (ap_sig_48.read()) {
        ap_sig_cseq_ST_st4_fsm_3 = ap_const_logic_1;
    } else {
        ap_sig_cseq_ST_st4_fsm_3 = ap_const_logic_0;
    }
}

void lcddrv_read_mem::thread_ap_sig_cseq_ST_st5_fsm_4() {
    if (ap_sig_64.read()) {
        ap_sig_cseq_ST_st5_fsm_4 = ap_const_logic_1;
    } else {
        ap_sig_cseq_ST_st5_fsm_4 = ap_const_logic_0;
    }
}

void lcddrv_read_mem::thread_ap_sig_cseq_ST_st6_fsm_5() {
    if (ap_sig_73.read()) {
        ap_sig_cseq_ST_st6_fsm_5 = ap_const_logic_1;
    } else {
        ap_sig_cseq_ST_st6_fsm_5 = ap_const_logic_0;
    }
}

void lcddrv_read_mem::thread_mem_ack_read_read_fu_55_p2() {
    mem_ack_read_read_fu_55_p2 = mem_ack.read();
}

void lcddrv_read_mem::thread_mem_addr() {
    mem_addr = addr.read();
}

void lcddrv_read_mem::thread_mem_addr_ap_vld() {
    if ((esl_seteq<1,1,1>(ap_const_logic_1, ap_sig_cseq_ST_st4_fsm_3.read()) || 
         esl_seteq<1,1,1>(ap_const_logic_1, ap_sig_cseq_ST_st2_fsm_1.read()))) {
        mem_addr_ap_vld = ap_const_logic_1;
    } else {
        mem_addr_ap_vld = ap_const_logic_0;
    }
}

void lcddrv_read_mem::thread_mem_req() {
    if (esl_seteq<1,1,1>(ap_const_logic_1, ap_sig_cseq_ST_st5_fsm_4.read())) {
        mem_req = ap_const_lv1_0;
    } else if ((esl_seteq<1,1,1>(ap_const_logic_1, ap_sig_cseq_ST_st4_fsm_3.read()) || 
                esl_seteq<1,1,1>(ap_const_logic_1, ap_sig_cseq_ST_st2_fsm_1.read()))) {
        mem_req = ap_const_lv1_1;
    } else {
        mem_req = "X";
    }
}

void lcddrv_read_mem::thread_mem_req_ap_vld() {
    if ((esl_seteq<1,1,1>(ap_const_logic_1, ap_sig_cseq_ST_st4_fsm_3.read()) || 
         esl_seteq<1,1,1>(ap_const_logic_1, ap_sig_cseq_ST_st2_fsm_1.read()) || 
         esl_seteq<1,1,1>(ap_const_logic_1, ap_sig_cseq_ST_st5_fsm_4.read()))) {
        mem_req_ap_vld = ap_const_logic_1;
    } else {
        mem_req_ap_vld = ap_const_logic_0;
    }
}

void lcddrv_read_mem::thread_ap_NS_fsm() {
    switch (ap_CS_fsm.read().to_uint64()) {
        case 1 : 
            if (!esl_seteq<1,1,1>(ap_start.read(), ap_const_logic_0)) {
                ap_NS_fsm = ap_ST_st2_fsm_1;
            } else {
                ap_NS_fsm = ap_ST_st1_fsm_0;
            }
            break;
        case 2 : 
            ap_NS_fsm = ap_ST_st3_fsm_2;
            break;
        case 4 : 
            ap_NS_fsm = ap_ST_st4_fsm_3;
            break;
        case 8 : 
            if (!esl_seteq<1,1,1>(ap_const_lv1_0, mem_ack_read_read_fu_55_p2.read())) {
                ap_NS_fsm = ap_ST_st5_fsm_4;
            } else {
                ap_NS_fsm = ap_ST_st4_fsm_3;
            }
            break;
        case 16 : 
            ap_NS_fsm = ap_ST_st6_fsm_5;
            break;
        case 32 : 
            ap_NS_fsm = ap_ST_st1_fsm_0;
            break;
        default : 
            ap_NS_fsm =  (sc_lv<6>) ("XXXXXX");
            break;
    }
}

}

