// ==============================================================
// 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_wait_tmr.h"
#include "AESL_pkg.h"

using namespace std;

namespace ap_rtl {

const sc_logic lcddrv_wait_tmr::ap_const_logic_1 = sc_dt::Log_1;
const sc_logic lcddrv_wait_tmr::ap_const_logic_0 = sc_dt::Log_0;
const sc_lv<3> lcddrv_wait_tmr::ap_ST_st1_fsm_0 = "1";
const sc_lv<3> lcddrv_wait_tmr::ap_ST_st2_fsm_1 = "10";
const sc_lv<3> lcddrv_wait_tmr::ap_ST_st3_fsm_2 = "100";
const sc_lv<32> lcddrv_wait_tmr::ap_const_lv32_0 = "00000000000000000000000000000000";
const sc_lv<1> lcddrv_wait_tmr::ap_const_lv1_1 = "1";
const sc_lv<32> lcddrv_wait_tmr::ap_const_lv32_2 = "10";
const sc_lv<24> lcddrv_wait_tmr::ap_const_lv24_0 = "000000000000000000000000";
const sc_lv<32> lcddrv_wait_tmr::ap_const_lv32_1 = "1";
const sc_lv<1> lcddrv_wait_tmr::ap_const_lv1_0 = "0";
const sc_lv<24> lcddrv_wait_tmr::ap_const_lv24_1 = "1";

lcddrv_wait_tmr::lcddrv_wait_tmr(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_st3_fsm_2 );
    sensitive << ( exitcond_fu_62_p2 );

    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_st3_fsm_2 );
    sensitive << ( exitcond_fu_62_p2 );

    SC_METHOD(thread_ap_sig_20);
    sensitive << ( ap_CS_fsm );

    SC_METHOD(thread_ap_sig_41);
    sensitive << ( ap_CS_fsm );

    SC_METHOD(thread_ap_sig_51);
    sensitive << ( ap_CS_fsm );

    SC_METHOD(thread_ap_sig_cseq_ST_st1_fsm_0);
    sensitive << ( ap_sig_20 );

    SC_METHOD(thread_ap_sig_cseq_ST_st2_fsm_1);
    sensitive << ( ap_sig_51 );

    SC_METHOD(thread_ap_sig_cseq_ST_st3_fsm_2);
    sensitive << ( ap_sig_41 );

    SC_METHOD(thread_dummy_tmr_out_o);
    sensitive << ( dummy_tmr_out_i );
    sensitive << ( ap_sig_cseq_ST_st3_fsm_2 );
    sensitive << ( exitcond_fu_62_p2 );
    sensitive << ( not_s_fu_73_p2 );

    SC_METHOD(thread_dummy_tmr_out_o_ap_vld);
    sensitive << ( ap_sig_cseq_ST_st3_fsm_2 );
    sensitive << ( exitcond_fu_62_p2 );

    SC_METHOD(thread_exitcond_fu_62_p2);
    sensitive << ( tmr );
    sensitive << ( ap_sig_cseq_ST_st3_fsm_2 );
    sensitive << ( t_cast_fu_58_p1 );

    SC_METHOD(thread_not_s_fu_73_p2);
    sensitive << ( dummy_tmr_out_i );

    SC_METHOD(thread_t_1_fu_67_p2);
    sensitive << ( t_reg_47 );

    SC_METHOD(thread_t_cast_fu_58_p1);
    sensitive << ( t_reg_47 );

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

    ap_CS_fsm = "001";
    static int apTFileNum = 0;
    stringstream apTFilenSS;
    apTFilenSS << "lcddrv_wait_tmr_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, tmr, "(port)tmr");
    sc_trace(mVcdFile, dummy_tmr_out_i, "(port)dummy_tmr_out_i");
    sc_trace(mVcdFile, dummy_tmr_out_o, "(port)dummy_tmr_out_o");
    sc_trace(mVcdFile, dummy_tmr_out_o_ap_vld, "(port)dummy_tmr_out_o_ap_vld");
#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_20, "ap_sig_20");
    sc_trace(mVcdFile, t_1_fu_67_p2, "t_1_fu_67_p2");
    sc_trace(mVcdFile, ap_sig_cseq_ST_st3_fsm_2, "ap_sig_cseq_ST_st3_fsm_2");
    sc_trace(mVcdFile, ap_sig_41, "ap_sig_41");
    sc_trace(mVcdFile, t_reg_47, "t_reg_47");
    sc_trace(mVcdFile, ap_sig_cseq_ST_st2_fsm_1, "ap_sig_cseq_ST_st2_fsm_1");
    sc_trace(mVcdFile, ap_sig_51, "ap_sig_51");
    sc_trace(mVcdFile, exitcond_fu_62_p2, "exitcond_fu_62_p2");
    sc_trace(mVcdFile, not_s_fu_73_p2, "not_s_fu_73_p2");
    sc_trace(mVcdFile, t_cast_fu_58_p1, "t_cast_fu_58_p1");
    sc_trace(mVcdFile, ap_NS_fsm, "ap_NS_fsm");
#endif

    }
}

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

}

void lcddrv_wait_tmr::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_st3_fsm_2.read()) && 
         esl_seteq<1,1,1>(exitcond_fu_62_p2.read(), ap_const_lv1_0))) {
        t_reg_47 = t_1_fu_67_p2.read();
    } else if (esl_seteq<1,1,1>(ap_const_logic_1, ap_sig_cseq_ST_st2_fsm_1.read())) {
        t_reg_47 = ap_const_lv24_0;
    }
}

void lcddrv_wait_tmr::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_st3_fsm_2.read()) && 
          !esl_seteq<1,1,1>(exitcond_fu_62_p2.read(), ap_const_lv1_0)))) {
        ap_done = ap_const_logic_1;
    } else {
        ap_done = ap_const_logic_0;
    }
}

void lcddrv_wait_tmr::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_wait_tmr::thread_ap_ready() {
    if ((esl_seteq<1,1,1>(ap_const_logic_1, ap_sig_cseq_ST_st3_fsm_2.read()) && 
         !esl_seteq<1,1,1>(exitcond_fu_62_p2.read(), ap_const_lv1_0))) {
        ap_ready = ap_const_logic_1;
    } else {
        ap_ready = ap_const_logic_0;
    }
}

void lcddrv_wait_tmr::thread_ap_sig_20() {
    ap_sig_20 = esl_seteq<1,1,1>(ap_CS_fsm.read().range(0, 0), ap_const_lv1_1);
}

void lcddrv_wait_tmr::thread_ap_sig_41() {
    ap_sig_41 = esl_seteq<1,1,1>(ap_const_lv1_1, ap_CS_fsm.read().range(2, 2));
}

void lcddrv_wait_tmr::thread_ap_sig_51() {
    ap_sig_51 = esl_seteq<1,1,1>(ap_const_lv1_1, ap_CS_fsm.read().range(1, 1));
}

void lcddrv_wait_tmr::thread_ap_sig_cseq_ST_st1_fsm_0() {
    if (ap_sig_20.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_wait_tmr::thread_ap_sig_cseq_ST_st2_fsm_1() {
    if (ap_sig_51.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_wait_tmr::thread_ap_sig_cseq_ST_st3_fsm_2() {
    if (ap_sig_41.read()) {
        ap_sig_cseq_ST_st3_fsm_2 = ap_const_logic_1;
    } else {
        ap_sig_cseq_ST_st3_fsm_2 = ap_const_logic_0;
    }
}

void lcddrv_wait_tmr::thread_dummy_tmr_out_o() {
    if ((esl_seteq<1,1,1>(ap_const_logic_1, ap_sig_cseq_ST_st3_fsm_2.read()) && 
         esl_seteq<1,1,1>(exitcond_fu_62_p2.read(), ap_const_lv1_0))) {
        dummy_tmr_out_o = not_s_fu_73_p2.read();
    } else {
        dummy_tmr_out_o = dummy_tmr_out_i.read();
    }
}

void lcddrv_wait_tmr::thread_dummy_tmr_out_o_ap_vld() {
    if ((esl_seteq<1,1,1>(ap_const_logic_1, ap_sig_cseq_ST_st3_fsm_2.read()) && 
         esl_seteq<1,1,1>(exitcond_fu_62_p2.read(), ap_const_lv1_0))) {
        dummy_tmr_out_o_ap_vld = ap_const_logic_1;
    } else {
        dummy_tmr_out_o_ap_vld = ap_const_logic_0;
    }
}

void lcddrv_wait_tmr::thread_exitcond_fu_62_p2() {
    exitcond_fu_62_p2 = (!t_cast_fu_58_p1.read().is_01() || !tmr.read().is_01())? sc_lv<1>(): sc_lv<1>(t_cast_fu_58_p1.read() == tmr.read());
}

void lcddrv_wait_tmr::thread_not_s_fu_73_p2() {
    not_s_fu_73_p2 = (dummy_tmr_out_i.read() ^ ap_const_lv1_1);
}

void lcddrv_wait_tmr::thread_t_1_fu_67_p2() {
    t_1_fu_67_p2 = (!t_reg_47.read().is_01() || !ap_const_lv24_1.is_01())? sc_lv<24>(): (sc_biguint<24>(t_reg_47.read()) + sc_biguint<24>(ap_const_lv24_1));
}

void lcddrv_wait_tmr::thread_t_cast_fu_58_p1() {
    t_cast_fu_58_p1 = esl_zext<25,24>(t_reg_47.read());
}

void lcddrv_wait_tmr::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 : 
            if (!esl_seteq<1,1,1>(exitcond_fu_62_p2.read(), ap_const_lv1_0)) {
                ap_NS_fsm = ap_ST_st1_fsm_0;
            } else {
                ap_NS_fsm = ap_ST_st3_fsm_2;
            }
            break;
        default : 
            ap_NS_fsm = "XXX";
            break;
    }
}

}

